
jmms.testing.generators.CrudUpdateGen 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 leap.web.api.meta.model.MApiParameter;
import java.util.Map;
class CrudUpdateGen extends CrudGen {
public CrudUpdateGen(TestTarget target, MetaTestSuite suite, SwaggerOp op) {
super(target, suite, op);
}
void gen() {
MetaTestStep step = createRestUpdateStep();
if(null != step) {
MetaTestCase test = newTestCase("update");
addCreateCascadeStep(test);
test.addStep(step);
addFindAndCompareStep(test);
suite.addTest(test);
}
}
private MetaTestStep createRestUpdateStep() {
MetaTestStep step = newRestStep("update record");
//add id params
for(MApiParameter p : pathParameters) {
step.setParam("path", p.getName(), evalCreate(entity.getName(), p.getName()));
}
//gen record
Map record = dg.genUpdate(target, entity, model);
if(record.isEmpty()){
return null;
}
//add body params
step.setParam("body", record);
return 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", evalCreate(entity.getName(), "id"));
MetaTestAssertion assertion = new MetaTestAssertion();
assertion.setTitle("updated fields should includes request fields");
assertion.setExpr("Assert.include(find." + entity.getName() + ", rest.params.body)");
step.addAssert(assertion);
test.addStep(step);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy