All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jmms.testing.generators.CrudCreateGen Maven / Gradle / Ivy

/*
 * Copyright 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package jmms.testing.generators;

import jmms.core.model.MetaTestAssertion;
import jmms.core.model.MetaTestCase;
import jmms.core.model.MetaTestStep;
import jmms.core.model.MetaTestSuite;
import jmms.testing.TestTarget;
import jmms.testing.actions.CrudCreateAction;

import java.util.Map;

class CrudCreateGen extends CrudGen {

    public CrudCreateGen(TestTarget target, MetaTestSuite suite, SwaggerOp op) {
        super(target, suite, op);
    }

    void gen() {
        MetaTestCase test = newTestCase("create");

        addCreateDepSteps(test);
        addRestCreateSelfStep(test);
        addFindAndCompareStep(test);

        suite.addTest(test);
    }

    private void addRestCreateSelfStep(MetaTestCase test) {
        MetaTestStep step = newRestStep("create record");
        step.setParam("body", genCreateBody());
        test.addStep(step);
    }

    private void addIdStep(MetaTestCase test) {
        MetaTestStep step = newCrudStep("ID", "resolve id from response");
        step.setParam("record", eval("rest.response.json"));
        test.addStep(step);
    }

    private void addFindAndCompareStep(MetaTestCase test) {
        MetaTestStep step = new MetaTestStep();
        step.setTitle("compare fields");
        step.setType("crud");
        step.setExec("FIND " + entity.getName());
        step.setParam("id", eval("$id('" + entity.getName() + "',rest.response.json)"));

        MetaTestAssertion assertion = new MetaTestAssertion();
        assertion.setTitle("created fields should includes request fields");
        assertion.setExpr("Assert.include(find." + entity.getName() + ", rest.params.body)");
        step.addAssert(assertion);

        test.addStep(step);
    }

    private Map genCreateBody() {
        return CrudCreateAction.withForeign(entity, dg.genCreate(target, entity, op.getMetaModel()));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy