Skip to content

Commit

Permalink
[#690] Test coverage: Increase test coverage for TraversalVisitor and…
Browse files Browse the repository at this point in the history
… JsonDMNSerializer.
  • Loading branch information
opatrascoiu committed Jul 24, 2024
1 parent 02b9d14 commit 7eeeb9d
Show file tree
Hide file tree
Showing 5 changed files with 5,777 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public Element<T> visit(ListTest<T> element, C context) {
//
@Override
public Element<T> visit(FunctionDefinition<T> element, C context) {
if (element == null) {
return null;
}

element.getBody().accept(this, context);
element.getFormalParameters().forEach(p -> p.accept(this, context));
return element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static boolean isDMNFile(File file) {
private final boolean validateSchema;
private final DMNDialectTransformer dmnTransformer;

public DMNSerializer(BuildLogger logger, DMNMarshaller dmnMarshaller, boolean validateSchema) {
protected DMNSerializer(BuildLogger logger, DMNMarshaller dmnMarshaller, boolean validateSchema) {
this.logger = logger;
this.dmnMarshaller = dmnMarshaller;
this.validateSchema = validateSchema;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2016 Goldman Sachs.
*
* 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 com.gs.dmn.feel.analysis.syntax.ast.visitor;

import com.gs.dmn.context.DMNContext;
import com.gs.dmn.el.analysis.semantics.type.Type;
import com.gs.dmn.error.NopErrorHandler;
import com.gs.dmn.feel.analysis.syntax.ast.Element;
import com.gs.dmn.feel.analysis.syntax.ast.Visitor;

public class TraversalVisitorTest extends BaseVisitorTest {
@Override
protected Visitor<Type, DMNContext, Element<Type>> getVisitor() {
return new TraversalVisitor<>(NopErrorHandler.INSTANCE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2016 Goldman Sachs.
*
* 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 com.gs.dmn.serialization;

import com.gs.dmn.AbstractTest;
import com.gs.dmn.ast.*;
import com.gs.dmn.serialization.jackson.JsonDMNSerializer;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

public class JsonDMNSerializerTest extends AbstractTest {
private final DMNSerializer dmnSerializer = new JsonDMNSerializer(LOGGER, false);

@Test
public void testRead() {
File input = new File(resource("jackson/v1_3/0004-lending.dmn"));

List<TDefinitions> definitionsList = this.dmnSerializer.readModels(Arrays.asList(input));
assertEquals(1, definitionsList.size());
List<TDRGElement> drgElementList = definitionsList.get(0).getDrgElement();
assertEquals(24, drgElementList.size());

TDecision decision = (TDecision) drgElementList.get(0);
assertNamedElement(decision, "d_BureauCallType", "BureauCallType");
assertVariable(decision, "BureauCallType", null, "tBureauCallType");
assertEquals(1, decision.getInformationRequirement().size());
assertEquals(1, decision.getKnowledgeRequirement().size());

TExpression expression = decision.getExpression();
assertTrue(expression instanceof TInvocation);
TInvocation invocation = (TInvocation) expression;
assertNotNull(invocation.getExpression(), "Missing expression");
}

private void assertNamedElement(TNamedElement decision, String id, String name) {
assertEquals(id, decision.getId(), "Incorrect ID");
assertEquals(name, decision.getName(), "Incorrect name");
}

private void assertVariable(TDecision decision, String id, String name, String typeRef) {
TInformationItem variable = decision.getVariable();
assertEquals(id, variable.getName(), "Incorrect name");
assertEquals(name, variable.getLabel(), "Incorrect label");
assertEquals(typeRef, variable.getTypeRef().getLocalPart(), "Incorrect typeRef");
}
}
Loading

0 comments on commit 7eeeb9d

Please sign in to comment.