Skip to content

Commit

Permalink
Template set deployables test optimizations (#1515)
Browse files Browse the repository at this point in the history
* update mockito and Hamcrest

* adapt TemplatedProcessingTest to work as expected

* #1452 fixed eclipse build.properties and .classpath

* #1452 implemented requested changes
changed cobigenHome from File to Path

* #1452 implemented requested changes

* #1452 removed unnecessary lambda because of more effective mockito

* Revert "#1452 removed unnecessary lambda because of more effective mockito"

This reverts commit e85dde5.

* test without mockito partial mock

* #1452 re-introduced mockito changes with latest changes from template-set-deployables
renamed findTemplateSetJarsWithBackwardsCompatibilityTest to findTemplateSetsDownloadedFolderTest
fixed logic of findTemplateSetsDownloadedFolderTest

Co-authored-by: LarsReinken <[email protected]>
  • Loading branch information
jan-vcapgemini and LarsReinken authored Apr 11, 2022
1 parent 54e3436 commit 36ab7ce
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 173 deletions.
5 changes: 2 additions & 3 deletions cobigen-eclipse/cobigen-eclipse-test/.classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/awaitility.jar" sourcepath="C:/Users/mbrunnli/.m2/repository/org/awaitility/awaitility/4.1.1/awaitility-4.1.1-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hamcrest.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java/">
Expand All @@ -17,7 +15,6 @@
<classpathentry exported="true" kind="lib" path="lib/error_prone_annotations.jar"/>
<classpathentry exported="true" kind="lib" path="lib/failureaccess.jar"/>
<classpathentry exported="true" kind="lib" path="lib/guava.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hamcrest-core.jar"/>
<classpathentry exported="true" kind="lib" path="lib/j2objc-annotations.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jcl-over-slf4j.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jsr305.jar"/>
Expand All @@ -32,5 +29,7 @@
<classpathentry exported="true" kind="lib" path="lib/system-lambda.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xmlunit.jar"/>
<classpathentry exported="true" kind="lib" path="lib/zt-exec.jar"/>
<classpathentry exported="true" kind="lib" path="lib/awaitility.jar" sourcepath="C:/Users/mbrunnli/.m2/repository/org/awaitility/awaitility/4.1.1/awaitility-4.1.1-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hamcrest.jar"/>
<classpathentry kind="output" path="eclipse-target/classes"/>
</classpath>
1 change: 0 additions & 1 deletion cobigen-eclipse/cobigen-eclipse-test/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ bin.includes = .,\
lib/error_prone_annotations.jar,\
lib/failureaccess.jar,\
lib/guava.jar,\
lib/hamcrest-core.jar,\
lib/j2objc-annotations.jar,\
lib/jcl-over-slf4j.jar,\
lib/jsr305.jar,\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.devonfw.cobigen.systemtest;

import static com.devonfw.cobigen.api.assertj.CobiGenAsserts.assertThat;
import static com.devonfw.cobigen.test.matchers.CustomHamcrestMatchers.hasItemsInList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.internal.matchers.Any.ANY;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;

import java.io.File;
import java.nio.charset.Charset;
import java.nio.file.Paths;
import java.util.List;

import org.hamcrest.Matcher;
import org.junit.Test;

import com.devonfw.cobigen.api.CobiGen;
Expand All @@ -27,9 +26,11 @@
import com.devonfw.cobigen.api.matchers.VariableAssignmentToMatcher;
import com.devonfw.cobigen.api.to.GenerationReportTo;
import com.devonfw.cobigen.api.to.TemplateTo;
import com.devonfw.cobigen.api.to.VariableAssignmentTo;
import com.devonfw.cobigen.impl.CobiGenFactory;
import com.devonfw.cobigen.impl.extension.PluginRegistry;
import com.devonfw.cobigen.systemtest.common.AbstractApiTest;
import com.devonfw.cobigen.test.matchers.CustomHamcrestMatchers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;

Expand Down Expand Up @@ -72,7 +73,6 @@ public void callClassLoadingTest() throws Exception {
assertThat(report).isSuccessful();
assertThat(generatedFile).exists();
assertThat(generatedFile).isFile().hasSameContentAs(expectedResult);

}

@Test
Expand Down Expand Up @@ -140,24 +140,27 @@ public String toString() {
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);

when(inputReader.isValidInput(any())).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(container)))))
.thenReturn(false);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), ANY, sameInstance(container)))))
.thenReturn(true);
when(matcher.matches(argThat(
new MatcherToMatcher(equalTo("fqn"), org.hamcrest.CoreMatchers.any(String.class), sameInstance(container)))))
.thenReturn(false);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), org.hamcrest.CoreMatchers.any(String.class),
sameInstance(container))))).thenReturn(true);

// Simulate container children resolution of any plug-in
when(inputReader.getInputObjects(any(), any(Charset.class))).thenReturn(Lists.newArrayList(firstChildResource));

when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(firstChildResource)))))
.thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), org.hamcrest.CoreMatchers.any(String.class),
sameInstance(firstChildResource))))).thenReturn(true);

// Simulate variable resolving of any plug-in
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(firstChildResource))),
argThat(hasItemsInList(
//
new VariableAssignmentToMatcher(equalTo("regex"), equalTo("rootPackage"), equalTo("1"), equalTo(false)),
new VariableAssignmentToMatcher(equalTo("regex"), equalTo("entityName"), equalTo("3"), equalTo(false)))),
any()))
Matcher<VariableAssignmentTo> m1 = new VariableAssignmentToMatcher(equalTo("regex"), equalTo("rootPackage"),
equalTo("1"), equalTo(false));
Matcher<VariableAssignmentTo> m2 = new VariableAssignmentToMatcher(equalTo("regex"), equalTo("entityName"),
equalTo("3"), equalTo(false));
Matcher<List<VariableAssignmentTo>> tmp = CustomHamcrestMatchers.hasItemsInList(m1, m2);
// IsIterableContaining<VariableAssignmentTo> t1 = new IsIterableContaining<>();
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("fqn"),
org.hamcrest.CoreMatchers.any(String.class), sameInstance(firstChildResource))), argThat(tmp), any()))
.thenReturn(ImmutableMap.<String, String> builder().put("rootPackage", "com.devonfw")
.put("entityName", "Test").build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import static com.devonfw.cobigen.api.assertj.CobiGenAsserts.assertThat;
import static com.devonfw.cobigen.test.matchers.CustomHamcrestMatchers.hasItemsInList;
import static org.hamcrest.CoreMatchers.any;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyList;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.internal.matchers.Any.ANY;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;

import java.io.File;
import java.nio.charset.Charset;
Expand All @@ -20,6 +19,7 @@

import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import com.devonfw.cobigen.api.CobiGen;
import com.devonfw.cobigen.api.extension.GeneratorPluginActivator;
Expand Down Expand Up @@ -251,26 +251,34 @@ public String toString() {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);

when(inputReader.isValidInput(any())).thenReturn(true);
when(inputReader.isValidInput(Mockito.any())).thenReturn(true);

// Simulate container children resolution of any plug-in
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child1))), anyList(),
any())).thenReturn(ImmutableMap.<String, String> builder().put("variable", "child1").build());
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child2))), anyList(),
any())).thenReturn(ImmutableMap.<String, String> builder().put("variable", "child2").build());
when(inputReader.getInputObjects(any(), any(Charset.class))).thenReturn(Lists.newArrayList(child1, child2));
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(child1))),
anyList(), Mockito.any()))
.thenReturn(ImmutableMap.<String, String> builder().put("variable", "child1").build());
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(child2))),
anyList(), Mockito.any()))
.thenReturn(ImmutableMap.<String, String> builder().put("variable", "child2").build());
when(inputReader.getInputObjects(Mockito.any(), Mockito.any(Charset.class)))
.thenReturn(Lists.newArrayList(child1, child2));

// match container
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("container"), ANY, sameInstance(container)))))
.thenReturn(true);
when(matcher
.matches(argThat(new MatcherToMatcher(equalTo("container"), any(String.class), sameInstance(container)))))
.thenReturn(true);

// do not match first child
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child1))))).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(child1))))).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(child1)))))
.thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(child1)))))
.thenReturn(true);

// match second child
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child2))))).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(child2))))).thenReturn(false);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(child2)))))
.thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(child2)))))
.thenReturn(false);

PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);

Expand Down Expand Up @@ -346,10 +354,10 @@ public String toString() {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);

when(inputReader.isValidInput(any())).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(container)))))
when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(container)))))
.thenReturn(false);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), ANY, sameInstance(container)))))
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), any(String.class), sameInstance(container)))))
.thenReturn(true);

// Simulate container children resolution of any plug-in
Expand All @@ -361,22 +369,25 @@ public String toString() {
return "child2";
}
};
when(inputReader.getInputObjects(any(), any(Charset.class)))
when(inputReader.getInputObjects(Mockito.any(), Mockito.any(Charset.class)))
.thenReturn(Lists.newArrayList(firstChildResource, secondChildResource));
} else {
when(inputReader.getInputObjects(any(), any(Charset.class))).thenReturn(Lists.newArrayList(firstChildResource));
when(inputReader.getInputObjects(Mockito.any(), Mockito.any(Charset.class)))
.thenReturn(Lists.newArrayList(firstChildResource));
}

when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(firstChildResource)))))
.thenReturn(containerChildMatchesTrigger);
when(matcher
.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(firstChildResource)))))
.thenReturn(containerChildMatchesTrigger);

// Simulate variable resolving of any plug-in
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(firstChildResource))),
when(matcher.resolveVariables(
argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(firstChildResource))),
argThat(hasItemsInList(
//
new VariableAssignmentToMatcher(equalTo("regex"), equalTo("rootPackage"), equalTo("1"), equalTo(false)),
new VariableAssignmentToMatcher(equalTo("regex"), equalTo("entityName"), equalTo("3"), equalTo(false)))),
any()))
Mockito.any()))
.thenReturn(ImmutableMap.<String, String> builder().put("rootPackage", "com.devonfw")
.put("entityName", "Test").build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import static com.devonfw.cobigen.api.assertj.CobiGenAsserts.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.hamcrest.CoreMatchers.any;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.internal.matchers.Any.ANY;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;

import java.io.File;
import java.io.FileWriter;
Expand All @@ -23,6 +22,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.mockito.Mockito;

import com.devonfw.cobigen.api.CobiGen;
import com.devonfw.cobigen.api.exception.InvalidConfigurationException;
Expand Down Expand Up @@ -165,13 +165,15 @@ public String toString() {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);

when(inputReader.isValidInput(any())).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(input))))).thenReturn(true);
when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(input)))))
.thenReturn(true);

// Simulate variable resolving of any plug-in
HashMap<String, String> variables = new HashMap<>(1);
variables.put("contextVar", "contextValue");
when(matcher.resolveVariables(any(MatcherTo.class), any(List.class), any())).thenReturn(variables);
when(matcher.resolveVariables(Mockito.any(MatcherTo.class), Mockito.any(List.class), Mockito.any()))
.thenReturn(variables);

PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);

Expand Down Expand Up @@ -218,13 +220,15 @@ public String toString() {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);

when(inputReader.isValidInput(any())).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(input))))).thenReturn(true);
when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(input)))))
.thenReturn(true);

// Simulate variable resolving of any plug-in
HashMap<String, String> variables = new HashMap<>(1);
variables.put("contextVar", "contextValue");
when(matcher.resolveVariables(any(MatcherTo.class), any(List.class), any())).thenReturn(variables);
when(matcher.resolveVariables(Mockito.any(MatcherTo.class), Mockito.any(List.class), Mockito.any()))
.thenReturn(variables);

PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);

Expand Down
Loading

0 comments on commit 36ab7ce

Please sign in to comment.