zipFiles = new ArrayList<>();
+ ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(Paths.get(zipFile)));
+ ZipEntry zipEntry;
+ while ((zipEntry = zipInputStream.getNextEntry()) != null) {
+ if (!zipEntry.isDirectory()) {
+ zipFiles.add(zipEntry.getName());
+ }
+ }
+
+ assertEquals(expectedZipFiles, zipFiles);
+ }
+
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/automatic/JMeterElementUtilsTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/automatic/JMeterElementUtilsTest.java
index be56388..06e5e11 100644
--- a/src/test/java/com/blazemeter/jmeter/correlation/core/automatic/JMeterElementUtilsTest.java
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/automatic/JMeterElementUtilsTest.java
@@ -1,19 +1,52 @@
package com.blazemeter.jmeter.correlation.core.automatic;
+import static com.blazemeter.jmeter.correlation.JMeterTestUtils.setupUpdatedJMeter;
+import static com.blazemeter.jmeter.correlation.TestUtils.findTestFile;
+import static com.blazemeter.jmeter.correlation.core.automatic.JMeterElementUtils.convertSubTree;
import static com.blazemeter.jmeter.correlation.core.automatic.extraction.method.XmlBodyExtractor.getXmlPath;
+import com.blazemeter.jmeter.correlation.JMeterTestUtils;
import com.blazemeter.jmeter.correlation.TestUtils;
+
+import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+
import junit.framework.TestCase;
import org.apache.commons.lang3.StringUtils;
+import org.apache.jmeter.control.LoopController;
+import org.apache.jmeter.exceptions.IllegalUserActionException;
import org.apache.jmeter.extractor.XPathExtractor;
+import org.apache.jmeter.gui.GuiPackage;
+import org.apache.jmeter.gui.tree.JMeterTreeListener;
+import org.apache.jmeter.gui.tree.JMeterTreeModel;
+import org.apache.jmeter.gui.tree.JMeterTreeNode;
+import org.apache.jmeter.protocol.http.config.gui.HttpDefaultsGui;
+import org.apache.jmeter.protocol.http.control.CookieManager;
+import org.apache.jmeter.protocol.http.control.HeaderManager;
+import org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui;
+import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
+import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.save.SaveService;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jmeter.testelement.TestPlan;
+import org.apache.jmeter.testelement.WorkBench;
import org.apache.jmeter.threads.JMeterContext;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jmeter.threads.ThreadGroup;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.collections.HashTree;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
@@ -28,7 +61,9 @@ public class JMeterElementUtilsTest extends TestCase {
private JMeterContext jmctx;
private static final String VAL_NAME = "value";
private static final String VAL_NAME_NR = "value_matchNr";
-
+ private static final String TEST_ELEMENT_CLASS = "org.apache.jmeter.testelement";
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
@Before
public void setup() throws UnsupportedEncodingException {
@@ -165,4 +200,49 @@ public void shouldGenerateXmlExtractorFromPath() {
extractor.process();
assertEquals("", vars.get(VAL_NAME));
}
+ @Test
+ public void convertSubTreeShouldChangeKeyClassToTestElement() throws IllegalUserActionException {
+
+ // Create a new TestPlan
+ TestPlan testPlan = new TestPlan("My Test Plan");
+
+ // Create a ThreadGroup
+ ThreadGroup threadGroup = new ThreadGroup();
+ threadGroup.setName("My Thread Group");
+ threadGroup.setNumThreads(1);
+ threadGroup.setRampUp(1);
+ threadGroup.setSamplerController(new LoopController());
+
+ // Create an HTTPSampler
+ HTTPSamplerProxy httpSampler = new HTTPSamplerProxy();
+ httpSampler.setDomain("www.google.com");
+ httpSampler.setPath("/");
+ httpSampler.setMethod("GET");
+ httpSampler.setName("HTTP Request");
+
+ // Add the HTTPSampler to the ThreadGroup
+ threadGroup.addTestElement(httpSampler);
+ threadGroup.addIterationListener(new LoopController());
+
+ // Add the ThreadGroup to the TestPlan
+ testPlan.addTestElement(threadGroup);
+
+ // Create a JMeterTreeModel and add the TestPlan to it
+ JMeterTreeModel treeModel = new JMeterTreeModel();
+ treeModel.addComponent(testPlan, (JMeterTreeNode) treeModel.getRoot());
+
+ HashTree tree = treeModel.getTestPlan();
+
+ convertSubTree(tree);
+
+ checkTree(tree);
+
+ }
+
+ private void checkTree(HashTree tree) {
+ for (Object o : new ArrayList<>(tree.list())) {
+ assertTrue(o.getClass().getName().contains(TEST_ELEMENT_CLASS));
+ checkTree(tree.getTree(o));
+ }
+ }
}
\ No newline at end of file
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/automatic/NonGuiFilesExtractor.java b/src/test/java/com/blazemeter/jmeter/correlation/core/automatic/NonGuiFilesExtractor.java
new file mode 100644
index 0000000..f523442
--- /dev/null
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/automatic/NonGuiFilesExtractor.java
@@ -0,0 +1,115 @@
+package com.blazemeter.jmeter.correlation.core.automatic;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import kg.apc.emulators.TestJMeterUtils;
+import org.apache.commons.io.FileUtils;
+import org.apache.jmeter.JMeter;
+import org.apache.jmeter.exceptions.IllegalUserActionException;
+import org.apache.jmeter.gui.tree.JMeterTreeModel;
+import org.apache.jmeter.gui.tree.JMeterTreeNode;
+import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jorphan.collections.HashTree;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+
+/**
+ * Use this class to obtain certain Samplers and Results from a JMX and JTL files.
+ * Specially useful when you want to simulate some scenarios without the need of
+ * opening JMeter GUI and making the removals manually.
+ *
+ * Just like the NonGuiAcr class, you require to have the path to the files and
+ * where you want to output them.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class NonGuiFilesExtractor {
+ //Remember to use the absolute path of the files.
+ private static String jmxFilePath = "";
+ private static String recordingTracePath = "";
+ private static String finalTracePath = "";
+ private static String finalJmxPath = "";
+
+ @Before
+ public void setUp() {
+ TestJMeterUtils.createJmeterEnv();
+ }
+
+ /**
+ * This method will use the list of desired elements to filter both the JMX and JTL files.
+ */
+ @Test
+ public void shouldRemoveUndesiredElementsFromFiles()
+ throws IllegalUserActionException, IOException {
+ if (!hasNeededFiles(jmxFilePath, recordingTracePath, finalTracePath, finalJmxPath)) {
+ return;
+ }
+ List desiredElements = Arrays.asList("/wp-admin/-3",
+ "/wp-admin/edit.php-9",
+ "/wp-admin/post-new.php-11",
+ "/wp-admin/edit.php-17",
+ "/wp-login.php-21");
+ String newTestPlanPath = removeUndesiredRequests(desiredElements);
+ String newTracePath = removeUndesiredResponses(desiredElements);
+ FileUtils.copyFile(new File(newTracePath), new File(finalTracePath));
+ }
+
+ private String removeUndesiredRequests(List desiredElements)
+ throws IllegalUserActionException {
+ HashTree hashTree = JMeterElementUtils.getTestPlan(jmxFilePath);
+
+ JMeterTreeModel model = JMeterElementUtils.convertToTreeModel(hashTree);
+ List undesiredNodes = model.getNodesOfType(HTTPSamplerProxy.class).stream()
+ .filter(sampler -> !desiredElements.contains(sampler.getName()))
+ .collect(Collectors.toList());
+
+ for (JMeterTreeNode node : undesiredNodes) {
+ hashTree.remove(node);
+ model.removeNodeFromParent(node);
+ node.getTestElement().removed();
+ }
+
+ HashTree modifiedTestPlan = model.getTestPlan();
+ JMeter.convertSubTree(modifiedTestPlan);
+
+ return JMeterElementUtils.saveTestPlan(modifiedTestPlan, finalJmxPath);
+ }
+
+ private String removeUndesiredResponses(List desiredElements) {
+ Configuration configuration = new Configuration();
+ ResultFileParser parser = new ResultFileParser(configuration);
+ List results = parser
+ .loadFromFile(new File(recordingTracePath), true);
+ List cleanedResults = new ArrayList<>();
+ for (SampleResult result : results) {
+ if (!desiredElements.contains(result.getSampleLabel())) {
+ continue;
+ }
+ cleanedResults.add(result);
+ }
+ return ResultFileParser.saveToFile(cleanedResults);
+ }
+
+ protected boolean hasNeededFiles(String... files) {
+ for (String file : files) {
+ if (file == null) {
+ return false;
+ }
+
+ if (file.isEmpty()) {
+ return false;
+ }
+
+ if (!new File(file).exists()) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/suggestions/method/ComparisonMethodTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/suggestions/method/ComparisonMethodTest.java
index e4a9f36..928ae8d 100644
--- a/src/test/java/com/blazemeter/jmeter/correlation/core/suggestions/method/ComparisonMethodTest.java
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/suggestions/method/ComparisonMethodTest.java
@@ -114,7 +114,7 @@ private void mockGetRecordingMap(String path) {
private void mockGetRecordingResults(Configuration configuration) throws IOException {
String path = TestUtils
- .getFilePath("/recordings/recordingTrace/recordingForMendix.jtl", getClass());
+ .getFolderPath("/recordings/recordingTrace/recordingForMendix.jtl", getClass());
List results = new ResultFileParser(configuration)
.loadFromFile(new File(path), true);
when(context.getRecordingSampleResults()).thenReturn(results);
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplateDependencyTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplateDependencyTest.java
new file mode 100644
index 0000000..745b8fd
--- /dev/null
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplateDependencyTest.java
@@ -0,0 +1,96 @@
+package com.blazemeter.jmeter.correlation.core.templates;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class CorrelationTemplateDependencyTest {
+
+ private static final String CORRELATION_TEMPLATE_DEPENDENCY_NAME = "Test";
+ private static final String CORRELATION_TEMPLATE_DEPENDENCY_VERSION = "1.0";
+ private static final String CORRELATION_TEMPLATE_DEPENDENCY_URL = "www.google.com";
+
+ private static final String CORRELATION_TEMPLATE_DEPENDENCY_NAME_2 = "Test2";
+ private static final String CORRELATION_TEMPLATE_DEPENDENCY_VERSION_2 = "2.0";
+ private static final String CORRELATION_TEMPLATE_DEPENDENCY_URL_2 = "www.yahoo.com";
+ @Test
+ public void shouldSetNameWhenSetName() {
+ CorrelationTemplateDependency correlationTemplateDependency = new CorrelationTemplateDependency();
+ correlationTemplateDependency.setName(CORRELATION_TEMPLATE_DEPENDENCY_NAME);
+ assertEquals(CORRELATION_TEMPLATE_DEPENDENCY_NAME,correlationTemplateDependency.getName());
+ }
+
+ @Test
+ public void shouldSetVersionWhenSetVersion() {
+ CorrelationTemplateDependency correlationTemplateDependency = new CorrelationTemplateDependency();
+ correlationTemplateDependency.setVersion(CORRELATION_TEMPLATE_DEPENDENCY_VERSION);
+ assertEquals(CORRELATION_TEMPLATE_DEPENDENCY_VERSION,correlationTemplateDependency.getVersion());
+ }
+
+ @Test
+ public void shouldSetUrlWhenSetUrl() {
+ CorrelationTemplateDependency correlationTemplateDependency = new CorrelationTemplateDependency();
+ correlationTemplateDependency.setUrl(CORRELATION_TEMPLATE_DEPENDENCY_URL);
+ assertEquals(CORRELATION_TEMPLATE_DEPENDENCY_URL,correlationTemplateDependency.getUrl());
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDifferentKindOfObject() {
+ CorrelationTemplateDependency correlationTemplateDependency = new CorrelationTemplateDependency(
+ CORRELATION_TEMPLATE_DEPENDENCY_NAME, CORRELATION_TEMPLATE_DEPENDENCY_VERSION, CORRELATION_TEMPLATE_DEPENDENCY_URL);
+ assertFalse(correlationTemplateDependency.equals(""));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithObjectWithDifferentName() {
+ CorrelationTemplateDependency correlationTemplateDependency = new CorrelationTemplateDependency(
+ CORRELATION_TEMPLATE_DEPENDENCY_NAME, CORRELATION_TEMPLATE_DEPENDENCY_VERSION, CORRELATION_TEMPLATE_DEPENDENCY_URL);
+ CorrelationTemplateDependency correlationTemplateDependency2 = new CorrelationTemplateDependency(
+ CORRELATION_TEMPLATE_DEPENDENCY_NAME_2, CORRELATION_TEMPLATE_DEPENDENCY_VERSION, CORRELATION_TEMPLATE_DEPENDENCY_URL);
+ assertFalse(correlationTemplateDependency.equals(correlationTemplateDependency2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithObjectWithDifferentVersion() {
+ CorrelationTemplateDependency correlationTemplateDependency = new CorrelationTemplateDependency(
+ CORRELATION_TEMPLATE_DEPENDENCY_NAME, CORRELATION_TEMPLATE_DEPENDENCY_VERSION, CORRELATION_TEMPLATE_DEPENDENCY_URL);
+ CorrelationTemplateDependency correlationTemplateDependency2 = new CorrelationTemplateDependency(
+ CORRELATION_TEMPLATE_DEPENDENCY_NAME, CORRELATION_TEMPLATE_DEPENDENCY_VERSION_2, CORRELATION_TEMPLATE_DEPENDENCY_URL);
+ assertFalse(correlationTemplateDependency.equals(correlationTemplateDependency2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithObjectWithDifferentUrl() {
+ CorrelationTemplateDependency correlationTemplateDependency = new CorrelationTemplateDependency(
+ CORRELATION_TEMPLATE_DEPENDENCY_NAME, CORRELATION_TEMPLATE_DEPENDENCY_VERSION, CORRELATION_TEMPLATE_DEPENDENCY_URL);
+ CorrelationTemplateDependency correlationTemplateDependency2 = new CorrelationTemplateDependency(
+ CORRELATION_TEMPLATE_DEPENDENCY_NAME, CORRELATION_TEMPLATE_DEPENDENCY_VERSION, CORRELATION_TEMPLATE_DEPENDENCY_URL_2);
+ assertFalse(correlationTemplateDependency.equals(correlationTemplateDependency2));
+ }
+
+ @Test
+ public void shouldReturnTrueWhenEqualsWithSameObject() {
+ CorrelationTemplateDependency correlationTemplateDependency = new CorrelationTemplateDependency(
+ CORRELATION_TEMPLATE_DEPENDENCY_NAME, CORRELATION_TEMPLATE_DEPENDENCY_VERSION, CORRELATION_TEMPLATE_DEPENDENCY_URL);
+ assertTrue(correlationTemplateDependency.equals(correlationTemplateDependency));
+ }
+
+ @Test
+ public void shouldReturnTrueWhenEqualsWithObjectWithSameInfo() {
+ CorrelationTemplateDependency correlationTemplateDependency = new CorrelationTemplateDependency(
+ CORRELATION_TEMPLATE_DEPENDENCY_NAME, CORRELATION_TEMPLATE_DEPENDENCY_VERSION, CORRELATION_TEMPLATE_DEPENDENCY_URL);
+ CorrelationTemplateDependency correlationTemplateDependency2 = new CorrelationTemplateDependency(
+ CORRELATION_TEMPLATE_DEPENDENCY_NAME, CORRELATION_TEMPLATE_DEPENDENCY_VERSION, CORRELATION_TEMPLATE_DEPENDENCY_URL);
+ assertTrue(correlationTemplateDependency.equals(correlationTemplateDependency2));
+ }
+
+ @Test
+ public void shouldReturnCorrectStringWhenToString() {
+ CorrelationTemplateDependency correlationTemplateDependency = new CorrelationTemplateDependency(
+ CORRELATION_TEMPLATE_DEPENDENCY_NAME, CORRELATION_TEMPLATE_DEPENDENCY_VERSION, CORRELATION_TEMPLATE_DEPENDENCY_URL);
+ assertEquals("CorrelationTemplateDependency{name='Test', version='1.0', url='www.google.com'}",
+ correlationTemplateDependency.toString());
+ }
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplateVersionsTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplateVersionsTest.java
new file mode 100644
index 0000000..1d274cb
--- /dev/null
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplateVersionsTest.java
@@ -0,0 +1,72 @@
+package com.blazemeter.jmeter.correlation.core.templates;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class CorrelationTemplateVersionsTest {
+
+ private static final String CONFIG_NAME = "Test";
+ private static final String TEMPLATE_V1 = "1.1";
+ private static final String TEMPLATE_V2 = "1.2";
+ private static final String TEMPLATE_V3 = "1.3";
+
+
+ @Test
+ public void shouldReturnNameWhenGetName() {
+ List versionList = new ArrayList<>(Arrays.asList(TEMPLATE_V1, TEMPLATE_V2));
+ CorrelationTemplateVersions correlationTemplateVersions = new CorrelationTemplateVersions(CONFIG_NAME, versionList);
+ assertEquals(CONFIG_NAME, correlationTemplateVersions.getName());
+ }
+
+ @Test
+ public void shouldReturnTrueWhenEqualsWithItself() {
+ List versionList = new ArrayList<>(Arrays.asList(TEMPLATE_V1, TEMPLATE_V2));
+ CorrelationTemplateVersions correlationTemplateVersions = new CorrelationTemplateVersions(CONFIG_NAME, versionList);
+ assertTrue(correlationTemplateVersions.equals(correlationTemplateVersions));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithNull() {
+ List versionList = new ArrayList<>(Arrays.asList(TEMPLATE_V1, TEMPLATE_V2));
+ CorrelationTemplateVersions correlationTemplateVersions = new CorrelationTemplateVersions(CONFIG_NAME, versionList);
+ assertFalse(correlationTemplateVersions.equals(null));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithObjectWithDifferentClass() {
+ List versionList = new ArrayList<>(Arrays.asList(TEMPLATE_V1, TEMPLATE_V2));
+ CorrelationTemplateVersions correlationTemplateVersions = new CorrelationTemplateVersions(CONFIG_NAME, versionList);
+ assertFalse(correlationTemplateVersions.equals("null"));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithObjectWithDifferentName() {
+ List versionList = new ArrayList<>(Arrays.asList(TEMPLATE_V1, TEMPLATE_V2));
+ CorrelationTemplateVersions correlationTemplateVersions = new CorrelationTemplateVersions(CONFIG_NAME, versionList);
+ CorrelationTemplateVersions correlationTemplateVersions2 = new CorrelationTemplateVersions(CONFIG_NAME+2, versionList);
+ assertFalse(correlationTemplateVersions.equals(correlationTemplateVersions2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithObjectWithDifferentVerionList() {
+ List versionList = new ArrayList<>(Arrays.asList(TEMPLATE_V1, TEMPLATE_V2));
+ CorrelationTemplateVersions correlationTemplateVersions = new CorrelationTemplateVersions(CONFIG_NAME, versionList);
+ CorrelationTemplateVersions correlationTemplateVersions2 = new CorrelationTemplateVersions(CONFIG_NAME+2, new ArrayList<>(Arrays.asList(TEMPLATE_V3)));
+ assertFalse(correlationTemplateVersions.equals(correlationTemplateVersions2));
+ }
+
+ @Test
+ public void shouldReturnTrueWhenEqualsWithEqualObject() {
+ List versionList = new ArrayList<>(Arrays.asList(TEMPLATE_V1, TEMPLATE_V2));
+ CorrelationTemplateVersions correlationTemplateVersions = new CorrelationTemplateVersions(CONFIG_NAME, versionList);
+ CorrelationTemplateVersions correlationTemplateVersions2 = new CorrelationTemplateVersions(CONFIG_NAME, versionList);
+ assertTrue(correlationTemplateVersions.equals(correlationTemplateVersions2));
+ }
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplatesRepositoriesConfigurationTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplatesRepositoriesConfigurationTest.java
new file mode 100644
index 0000000..67bb4c0
--- /dev/null
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplatesRepositoriesConfigurationTest.java
@@ -0,0 +1,226 @@
+package com.blazemeter.jmeter.correlation.core.templates;
+
+import com.blazemeter.jmeter.correlation.core.templates.repository.RepositoryManager;
+import com.blazemeter.jmeter.correlation.core.templates.repository.TemplateProperties;
+import com.blazemeter.jmeter.correlation.core.templates.repository.pluggable.RemoteUrlRepository;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class CorrelationTemplatesRepositoriesConfigurationTest extends WiredBaseTest {
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+ private CorrelationTemplatesRepositoriesConfiguration correlationTempRepoConfig;
+ private LocalConfiguration localConfiguration;
+ private static final String WIRED_HOST = "localhost";
+ private static final String TEST_REPO_NAME = "test";
+ private static final String FIRST_TEMPLATE_NAME = "first";
+ private static final String SECOND_TEMPLATE_NAME = "second";
+ private static final String SIEBEL_TEMPLATE_NAME = "siebel";
+ private static final String TEMPLATE_VERSION_1_1 = "1.1";
+ private static final String TEMPLATE_VERSION_1_0 = "1.0";
+ private static final String TEMPLATE_DESCRIPTION = "Description1";
+ private static final String LOCAL_REPO_NAME = "local";
+ private static final String CENTRAL_REPO_NAME = "local";
+
+ @Before
+ public void setUp() throws IOException {
+ String path = folder.getRoot().getPath();
+ LocalConfiguration.installDefaultFiles(path);
+ localConfiguration = new LocalConfiguration(path, true);
+ localConfiguration.setupRepositoryManagers();
+ correlationTempRepoConfig = new CorrelationTemplatesRepositoriesConfiguration(localConfiguration);
+ }
+
+ @Test
+ public void shouldReturnRootPathWhenGetLocalRootFolder() {
+ String rootFolder = correlationTempRepoConfig.getLocalRootFolder();
+ assertEquals(folder.getRoot().getPath().toString(), rootFolder);
+ }
+
+ @Test
+ public void shouldReturnRepositoryManagerWhenGetRepositoryManagerWithNoURL() {
+ RepositoryManager repoManager = correlationTempRepoConfig.getRepositoryManager(LOCAL_REPO_NAME);
+ assertEquals(localConfiguration.getRepositoriesManagers().get(LOCAL_REPO_NAME), repoManager);
+ }
+
+ @Test
+ public void shouldReturnRepositoryManagerWhenGetRepositoryManager() {
+ RepositoryManager repoManager = correlationTempRepoConfig.getRepositoryManager(LOCAL_REPO_NAME, "");
+ assertEquals(localConfiguration.getRepositoriesManagers().get(LOCAL_REPO_NAME), repoManager);
+ }
+
+ @Test
+ public void shouldReturnNewRepoWhenGetRepositoryManagerWithUnexistingName() {
+ RepositoryManager expectedRepo = correlationTempRepoConfig.getRepositoryManager(TEST_REPO_NAME, "localhost");
+ assertEquals(expectedRepo.getName(), TEST_REPO_NAME);
+ assertEquals(expectedRepo.getEndPoint(), "localhost");
+ }
+
+ @Test
+ public void shouldSaveRepositoryWhenSaveRepository() throws IOException {
+ startWiredMock(WIRED_HOST);
+ mockRequestsToRepoFiles();
+ correlationTempRepoConfig.saveRepository(TEST_REPO_NAME, getBaseURL() + TEST_REPOSITORY_URL);
+ RepositoryManager repoManager = localConfiguration.getRepositoriesManagers().get(TEST_REPO_NAME);
+ assertEquals(TEST_REPO_NAME, repoManager.getName());
+ assertEquals(getBaseURL() + TEST_REPOSITORY_URL, repoManager.getEndPoint());
+ }
+
+ @Test
+ public void shouldDeleteRepositoryWhenDeleteRepository() throws IOException {
+ installTestRepo();
+ correlationTempRepoConfig.deleteRepository(TEST_REPO_NAME);
+ List repositories = localConfiguration.getRepositories();
+ assertTrue(repositories.stream().noneMatch(r -> r.getName().equals(TEST_REPO_NAME)));
+ }
+
+ private void installTestRepo() throws IOException {
+ startWiredMock(WIRED_HOST);
+ mockRequestsToRepoFiles();
+ RepositoryManager testRepo = createRemoteRepository();
+ ((CorrelationTemplatesRepositoriesRegistry) testRepo.getTemplateRegistry()).save(TEST_REPO_NAME, getBaseURL() + TEST_REPOSITORY_URL);
+ localConfiguration.addRepositoryManager(testRepo);
+ localConfiguration.setupRepositoryManagers();
+ }
+ private RemoteUrlRepository createRemoteRepository() {
+ RemoteUrlRepository testRepo = new RemoteUrlRepository();
+ testRepo.setName(TEST_REPO_NAME);
+ testRepo.setEndPoint(getBaseURL() + TEST_REPOSITORY_URL);
+ testRepo.setConfig(localConfiguration);
+ testRepo.init();
+ return testRepo;
+ }
+
+ @Test
+ public void shouldReturnCorrelationRepositoriesWhenGetCorrelationRepositories() throws IOException {
+ installTestRepo();
+ List repositories = correlationTempRepoConfig.getCorrelationRepositories();
+ assertTrue(repositories.stream().anyMatch(r -> r.getName().equals(TEST_REPO_NAME)));
+ assertTrue(repositories.stream().anyMatch(r -> r.getName().equals(LOCAL_REPO_NAME)));
+ assertTrue(repositories.stream().anyMatch(r -> r.getName().equals(CENTRAL_REPO_NAME)));
+ }
+
+ @Test
+ public void shouldReturnCorrelationTemplateVersionsWhenGetCorrelationTemplateVersionsByRepositoryNameWithUseLocal() throws IOException {
+ installTestRepo();
+ String expectedFirstCorrelationTemplateVersions = "CorrelationTemplateVersions {versions=[1.0, 1.1]}";
+ String expectedSecondCorrelationTemplateVersions = "CorrelationTemplateVersions {versions=[1.0]}";
+
+ Map correlationTemplateVersions =
+ correlationTempRepoConfig.getCorrelationTemplateVersionsByRepositoryName(TEST_REPO_NAME, true);
+
+ assertEquals(expectedFirstCorrelationTemplateVersions, correlationTemplateVersions.get(FIRST_TEMPLATE_NAME).toString());
+ assertEquals(expectedSecondCorrelationTemplateVersions, correlationTemplateVersions.get(SECOND_TEMPLATE_NAME).toString());
+ }
+
+ @Test
+ public void shouldReturnCorrelationTemplateVersionsWhenGetCorrelationTemplateVersionsByRepositoryName() throws IOException {
+ installTestRepo();
+ String expectedFirstCorrelationTemplateVersions = "CorrelationTemplateVersions {versions=[1.0, 1.1]}";
+ String expectedSecondCorrelationTemplateVersions = "CorrelationTemplateVersions {versions=[1.0]}";
+
+ Map correlationTemplateVersions =
+ correlationTempRepoConfig.getCorrelationTemplateVersionsByRepositoryName(TEST_REPO_NAME, false);
+
+ assertEquals(expectedFirstCorrelationTemplateVersions, correlationTemplateVersions.get(FIRST_TEMPLATE_NAME).toString());
+ assertEquals(expectedSecondCorrelationTemplateVersions, correlationTemplateVersions.get(SECOND_TEMPLATE_NAME).toString());
+ }
+
+ @Test
+ public void shouldInstallTemplateWhenInstallTemplate() throws IOException, ConfigurationException {
+ installTestRepo();
+ correlationTempRepoConfig.installTemplate(TEST_REPO_NAME, FIRST_TEMPLATE_NAME, TEMPLATE_VERSION_1_1 );
+ assertTrue(localConfiguration.isInstalled(TEST_REPO_NAME, FIRST_TEMPLATE_NAME, TEMPLATE_VERSION_1_1));
+ }
+
+ @Test
+ public void shouldUninstallTemplateWhenUninstallTemplate() throws IOException, ConfigurationException {
+ installTestRepo();
+ localConfiguration.installTemplate(TEST_REPO_NAME, FIRST_TEMPLATE_NAME, TEMPLATE_VERSION_1_1);
+ correlationTempRepoConfig.uninstallTemplate(TEST_REPO_NAME, FIRST_TEMPLATE_NAME, TEMPLATE_VERSION_1_1 );
+ assertFalse(localConfiguration.isInstalled(TEST_REPO_NAME, FIRST_TEMPLATE_NAME, TEMPLATE_VERSION_1_1));
+ }
+
+ @Test
+ public void shouldReturnRepositoryUrlWhenGetRepositoryURL() throws IOException {
+ installTestRepo();
+ String repoURL = correlationTempRepoConfig.getRepositoryURL(TEST_REPO_NAME);
+ assertEquals(getBaseURL() + TEST_REPOSITORY_URL, repoURL);
+ }
+
+ @Test
+ public void shouldReturnTrueWhenIisLocalTemplateVersionSavedWithSavedVersion() {
+ assertTrue(correlationTempRepoConfig.isLocalTemplateVersionSaved(SIEBEL_TEMPLATE_NAME, TEMPLATE_VERSION_1_0));
+ }
+
+ @Test
+ public void shouldReturnCorrelationTemplatesAndPropertiesWhenGetCorrelationTemplatesAndPropertiesByRepositoryNameWithUseLocal() throws IOException {
+ installTestRepo();
+ Map templatesAndProperties =
+ correlationTempRepoConfig.getCorrelationTemplatesAndPropertiesByRepositoryName(TEST_REPO_NAME, true);
+ Iterator> iterator = templatesAndProperties.entrySet().iterator();
+ Map.Entry entry = iterator.next();
+ checkTemplate(entry.getKey(),
+ FIRST_TEMPLATE_NAME + "-" +TEMPLATE_VERSION_1_1,
+ TEMPLATE_DESCRIPTION, TEMPLATE_VERSION_1_1, TEST_REPO_NAME);
+ checkProperties(entry.getValue());
+ entry = iterator.next();
+ checkTemplate(entry.getKey(),
+ FIRST_TEMPLATE_NAME + "-" +TEMPLATE_VERSION_1_0,
+ TEMPLATE_DESCRIPTION, TEMPLATE_VERSION_1_0, TEST_REPO_NAME);
+ checkProperties(entry.getValue());
+ entry = iterator.next();
+ checkTemplate(entry.getKey(),
+ SECOND_TEMPLATE_NAME + "-" +TEMPLATE_VERSION_1_0,
+ TEMPLATE_DESCRIPTION, TEMPLATE_VERSION_1_0, TEST_REPO_NAME);
+ checkProperties(entry.getValue());
+ }
+
+ private void checkTemplate(Template temp, String id, String Description, String version, String repoId){
+ assertEquals(temp.getId(), id);
+ assertEquals(temp.getDescription(), Description);
+ assertEquals(temp.getVersion(), version);
+ assertEquals(temp.getRepositoryId(), repoId);
+ }
+
+ private void checkProperties(TemplateProperties props){
+ Assert.assertEquals("false", props.get("not_allow_export"));
+ Assert.assertEquals("false", props.get("disallow_to_use"));
+ }
+
+ @Test
+ public void shouldReturnCorrelationTemplatesAndPropertiesWhenGetCorrelationTemplatesAndPropertiesByRepositoryName() throws IOException {
+ installTestRepo();
+ Map templatesAndProperties =
+ correlationTempRepoConfig.getCorrelationTemplatesAndPropertiesByRepositoryName(TEST_REPO_NAME, false);
+ Iterator> iterator = templatesAndProperties.entrySet().iterator();
+ Map.Entry entry = iterator.next();
+ checkTemplate(entry.getKey(),
+ FIRST_TEMPLATE_NAME + "-" +TEMPLATE_VERSION_1_1,
+ TEMPLATE_DESCRIPTION, TEMPLATE_VERSION_1_1, TEST_REPO_NAME);
+ checkProperties(entry.getValue());
+ entry = iterator.next();
+ checkTemplate(entry.getKey(),
+ FIRST_TEMPLATE_NAME + "-" +TEMPLATE_VERSION_1_0,
+ TEMPLATE_DESCRIPTION, TEMPLATE_VERSION_1_0, TEST_REPO_NAME);
+ checkProperties(entry.getValue());
+ entry = iterator.next();
+ checkTemplate(entry.getKey(),
+ SECOND_TEMPLATE_NAME + "-" +TEMPLATE_VERSION_1_0,
+ TEMPLATE_DESCRIPTION, TEMPLATE_VERSION_1_0, TEST_REPO_NAME);
+ checkProperties(entry.getValue());
+ }
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplatesRepositoryConfigurationTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplatesRepositoryConfigurationTest.java
new file mode 100644
index 0000000..134b849
--- /dev/null
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplatesRepositoryConfigurationTest.java
@@ -0,0 +1,41 @@
+
+
+package com.blazemeter.jmeter.correlation.core.templates;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class CorrelationTemplatesRepositoryConfigurationTest {
+
+ private static final String CONFIG_NAME = "Test";
+ private static final String CONFIG_URL = "www.google.com";
+
+
+ @Test
+ public void shouldSetNameWhenSetName() {
+ CorrelationTemplatesRepositoryConfiguration correlationTemplatesRepositoryConfiguration =
+ new CorrelationTemplatesRepositoryConfiguration();
+ correlationTemplatesRepositoryConfiguration.setName(CONFIG_NAME);
+ assertEquals(CONFIG_NAME, correlationTemplatesRepositoryConfiguration.getName());
+ }
+
+ @Test
+ public void shouldSetUrlWhenSetUrl() {
+ CorrelationTemplatesRepositoryConfiguration correlationTemplatesRepositoryConfiguration =
+ new CorrelationTemplatesRepositoryConfiguration();
+ correlationTemplatesRepositoryConfiguration.setUrl(CONFIG_URL);
+ assertEquals(CONFIG_URL, correlationTemplatesRepositoryConfiguration.getUrl());
+ }
+
+ @Test
+ public void shouldReturnStringWhenToString() {
+ CorrelationTemplatesRepositoryConfiguration correlationTemplatesRepositoryConfiguration =
+ new CorrelationTemplatesRepositoryConfiguration(CONFIG_NAME, CONFIG_URL);
+ String expectedString = "CorrelationTemplatesRepositoryConfiguration{name='Test', "
+ +"url='www.google.com', "
+ +"installedTemplates={}}";
+ assertEquals(expectedString, correlationTemplatesRepositoryConfiguration.toString());
+ }
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplatesRepositoryTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplatesRepositoryTest.java
new file mode 100644
index 0000000..543e8be
--- /dev/null
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/CorrelationTemplatesRepositoryTest.java
@@ -0,0 +1,129 @@
+package com.blazemeter.jmeter.correlation.core.templates;
+
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class CorrelationTemplatesRepositoryTest {
+
+ private static final String REPOSITORY_NAME = "Test";
+
+ private static final String TEMPLATE_NAME = "Template";
+
+ private static final String TEMPLATE_V1 = "1.1";
+
+ private static final String TEMPLATE_V2 = "1.2";
+
+
+ @Test
+ public void shouldAddTemplateWhenAddTemplate() {
+ CorrelationTemplatesRepository correlationTemplatesRepository =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME);
+ correlationTemplatesRepository.addTemplate(TEMPLATE_NAME, TEMPLATE_V1);
+ Map.Entry entry = correlationTemplatesRepository.getTemplates().entrySet().iterator().next();
+ assertEquals(TEMPLATE_NAME, entry.getKey());
+ assertEquals("[" + TEMPLATE_V1 + "]", entry.getValue().getVersions().toString());
+ }
+
+ @Test
+ public void shouldEditTemplateVersionWhenAddTemplateWithNewTemplateVersion() {
+ CorrelationTemplatesRepository correlationTemplatesRepository =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME);
+ correlationTemplatesRepository.addTemplate(TEMPLATE_NAME, TEMPLATE_V1);
+ correlationTemplatesRepository.addTemplate(TEMPLATE_NAME, TEMPLATE_V2);
+ Map.Entry entry = correlationTemplatesRepository.getTemplates().entrySet().iterator().next();
+ assertEquals(TEMPLATE_NAME, entry.getKey());
+ assertEquals("[" + TEMPLATE_V1 + ", " + TEMPLATE_V2 + "]", entry.getValue().getVersions().toString());
+ }
+
+ @Test
+ public void shouldDoNothingWhenAddTemplateWithExistingTemplateVersion() {
+ CorrelationTemplatesRepository correlationTemplatesRepository =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME);
+ correlationTemplatesRepository.addTemplate(TEMPLATE_NAME, TEMPLATE_V1);
+ correlationTemplatesRepository.addTemplate(TEMPLATE_NAME, TEMPLATE_V1);
+ Map.Entry entry = correlationTemplatesRepository.getTemplates().entrySet().iterator().next();
+ assertEquals(TEMPLATE_NAME, entry.getKey());
+ assertEquals("[" + TEMPLATE_V1 + "]", entry.getValue().getVersions().toString());
+ }
+
+ @Test
+ public void shouldAddTemplateVersionWhenAddTemplateWithTamplateVersion() {
+ CorrelationTemplatesRepository correlationTemplatesRepository =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME);
+ correlationTemplatesRepository.addTemplate(TEMPLATE_NAME, new CorrelationTemplateVersions(TEMPLATE_V1));
+ Map.Entry entry = correlationTemplatesRepository.getTemplates().entrySet().iterator().next();
+ assertEquals(TEMPLATE_NAME, entry.getKey());
+ assertEquals("[" + TEMPLATE_V1 + "]", entry.getValue().getVersions().toString());
+ }
+
+ @Test
+ public void shouldSetNameWhenSetName() {
+ CorrelationTemplatesRepository correlationTemplatesRepository =
+ new CorrelationTemplatesRepository("");
+ correlationTemplatesRepository.setName(REPOSITORY_NAME);
+ assertEquals(REPOSITORY_NAME, correlationTemplatesRepository.getName());
+ }
+
+ @Test
+ public void shouldReturnTrueWhenEqualsWithItself() {
+ CorrelationTemplatesRepository correlationTemplatesRepository =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME);
+ assertTrue(correlationTemplatesRepository.equals(correlationTemplatesRepository));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithNullObject() {
+ CorrelationTemplatesRepository correlationTemplatesRepository =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME);
+ assertFalse(correlationTemplatesRepository.equals(null));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithObjectFromDifferentClass() {
+ CorrelationTemplatesRepository correlationTemplatesRepository =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME);
+ assertFalse(correlationTemplatesRepository.equals("null"));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDifferentNameObject() {
+ CorrelationTemplatesRepository correlationTemplatesRepository =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME);
+ CorrelationTemplatesRepository correlationTemplatesRepository2 =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME + 2);
+ assertFalse(correlationTemplatesRepository.equals(correlationTemplatesRepository2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDifferentTemplatesObject() {
+ CorrelationTemplatesRepository correlationTemplatesRepository =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME);
+ correlationTemplatesRepository.addTemplate(TEMPLATE_NAME, new CorrelationTemplateVersions(TEMPLATE_V1));
+ CorrelationTemplatesRepository correlationTemplatesRepository2 =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME);
+ correlationTemplatesRepository2.addTemplate(TEMPLATE_NAME, new CorrelationTemplateVersions(TEMPLATE_V2));
+ assertFalse(correlationTemplatesRepository.equals(correlationTemplatesRepository2));
+ }
+
+ @Test
+ public void shouldReturnTrueWhenEqualsWithEqualObjects() {
+ Map templatesVersions = new HashMap<>();
+ templatesVersions.put(TEMPLATE_NAME, new CorrelationTemplateVersions(TEMPLATE_V1));
+ CorrelationTemplatesRepository correlationTemplatesRepository =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME);
+ correlationTemplatesRepository.setTemplates(templatesVersions);
+ CorrelationTemplatesRepository correlationTemplatesRepository2 =
+ new CorrelationTemplatesRepository(REPOSITORY_NAME);
+ correlationTemplatesRepository2.setTemplates(templatesVersions);
+ assertTrue(correlationTemplatesRepository.equals(correlationTemplatesRepository2));
+ }
+
+
+
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/LocalConfigurationTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/LocalConfigurationTest.java
index be04f6e..233e6b5 100644
--- a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/LocalConfigurationTest.java
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/LocalConfigurationTest.java
@@ -1,33 +1,41 @@
package com.blazemeter.jmeter.correlation.core.templates;
import static com.blazemeter.jmeter.correlation.TestUtils.getFileContent;
-import static com.blazemeter.jmeter.correlation.core.templates.RepositoryGeneralConst.CENTRAL_REPOSITORY_NAME;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
-import static com.github.tomakehurst.wiremock.client.WireMock.head;
-import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
-import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
-import com.github.tomakehurst.wiremock.WireMockServer;
+
+import com.blazemeter.jmeter.correlation.TestUtils;
+import com.blazemeter.jmeter.correlation.core.templates.repository.RemoteRepository;
+import com.blazemeter.jmeter.correlation.core.templates.repository.RepositoryManager;
+import com.blazemeter.jmeter.correlation.core.templates.repository.TemplateProperties;
+import com.blazemeter.jmeter.correlation.core.templates.repository.pluggable.RemoteUrlRepository;
import com.github.tomakehurst.wiremock.client.MappingBuilder;
+
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
+import java.util.function.Consumer;
import java.util.stream.Collectors;
+
import org.assertj.core.api.JUnitSoftAssertions;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -37,408 +45,457 @@
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
-public class LocalConfigurationTest {
-
- private static final String VERSION_ONE = "1.0";
- private static final String DUMMY_FILE_VERSION_ONE = "dummy-1.0.jar";
- private static final String SIEBEL_REPO_NAME = "siebel";
- private static final String FIRST_REPO_NAME = "repository1";
- private static final String SECOND_REPO_NAME = "repository2";
- private static final String firstRepositoryURL = "localhost/firstRepository.json";
- private static final String secondRepositoryURL = "localhost/secondRepository.json";
- private static final String DEFAULT_ULR = "http://localhost.com/1";
- private static final String JAR_SUFFIX = ".jar";
- private static final String firstTemplateID = "firstTemplate";
- private static final String firstTemplateVersion = "1.0";
- private static final String REPOSITORY_ID = "R1";
-
- @Rule
- public TemporaryFolder folder = new TemporaryFolder();
- public JUnitSoftAssertions softly = new JUnitSoftAssertions();
- @Mock
- private CorrelationTemplateDependency firstDependency;
- @Mock
- private CorrelationTemplatesRepository localRepository;
- @Mock
- private CorrelationTemplatesRepository firstRepository;
- @Mock
- private CorrelationTemplatesRepository secondRepository;
- @Mock
- private CorrelationTemplatesRepositoryConfiguration repositoryWithInstalledTemplates;
- @Mock
- private CorrelationTemplatesRepositoryConfiguration localRepositoryConfiguration;
- @Mock
- private CorrelationTemplatesRepository expectedSiebelRepository;
- @Mock
- private CorrelationTemplatesRepository expectedCentralRepository;
- private final WireMockServer wireMockServer = new WireMockServer(wireMockConfig().dynamicPort());
- private LocalConfiguration configuration;
- private String dependenciesFolder;
- private static final String TEMPLATE_FILE_SUFFIX = "template.json";
-
- private static final String REPOSITORY_FILE_SUFFIX = "repository.json";
-
- private static final String LOCAL_REPOSITORY_NAME = "local";
- private static final String LOCAL_REPOSITORY_DISPLAY_NAME = "Local";
-
- private static final String CENTRAL_REPOSITORY_NAME = "central";
- private static final String CENTRAL_REPOSITORY_DISPLAY_NAME = "GitHub's Central";
-
- private static final String SIEBEL_TEMPLATE_REFERENCE_NAME = "siebel";
- private static final String WORDPRESS_TEMPLATE_REFERENCE_NAME = "wordpress";
- private static final String TEMPLATE_VERSION_TWO = "1.1";
- private static final String TEMPLATE_VERSION_ONE = "1.0";
-
- private static final String TEMPLATE_VERSION_THREE = "0.1-alpha";
-
- private static final String CORRELATION_TEMPLATES_REPOSITORY_NAME =
- "CorrelationTemplatesRepository";
-
- private static final String SIEBEL_TEMPLATE_VERSION_TWO_NAME =
- SIEBEL_TEMPLATE_REFERENCE_NAME + "-" + TEMPLATE_VERSION_TWO + "-" + TEMPLATE_FILE_SUFFIX;
- private static final String SIEBEL_TEMPLATE_VERSION_ONE_NAME =
- SIEBEL_TEMPLATE_REFERENCE_NAME + "-" + TEMPLATE_VERSION_ONE + "-" + TEMPLATE_FILE_SUFFIX;
-
- private static final String WORDPRESS_TEMPLATE_VERSION_ONE_NAME =
- WORDPRESS_TEMPLATE_REFERENCE_NAME + "-" + TEMPLATE_VERSION_ONE + "-" + TEMPLATE_FILE_SUFFIX;
-
- @Before
- public void setUp() {
- LocalConfiguration.installDefaultFiles(folder.getRoot().getPath());
- configuration = new LocalConfiguration(folder.getRoot().getPath(), true);
- configuration.setupRepositoryManagers();
- when(firstRepository.getName()).thenReturn(FIRST_REPO_NAME);
- when(secondRepository.getName()).thenReturn(SECOND_REPO_NAME);
- when(localRepository.getName()).thenReturn(LOCAL_REPOSITORY_NAME);
- configuration.addRepository(firstRepository.getName(), firstRepositoryURL);
- dependenciesFolder = folder.getRoot().getAbsolutePath() + "/lib/";
- prepareExpectedLocalRepository();
- }
-
- @After
- public void tearDown() {
- if (wireMockServer.isRunning()) {
- wireMockServer.stop();
- }
- }
- private void prepareExpectedLocalRepository() {
- when(expectedSiebelRepository.getValues()).thenReturn(
- CORRELATION_TEMPLATES_REPOSITORY_NAME + "{name='" + LOCAL_REPOSITORY_NAME
- + "', displayName='" + LOCAL_REPOSITORY_DISPLAY_NAME
- + "', templatesVersions={" + SIEBEL_TEMPLATE_REFERENCE_NAME +
- "=CorrelationTemplateVersions {versions=[" + TEMPLATE_VERSION_ONE + "]}}}");
-
- when(expectedCentralRepository.getValues()).thenReturn(
- CORRELATION_TEMPLATES_REPOSITORY_NAME + "{name='" + CENTRAL_REPOSITORY_NAME
- + "', displayName='" + CENTRAL_REPOSITORY_DISPLAY_NAME
- + "', templatesVersions={" + WORDPRESS_TEMPLATE_REFERENCE_NAME +
- "=CorrelationTemplateVersions {versions=[" + TEMPLATE_VERSION_THREE + "]}}}");
-
- }
-
- public void configureWireMockServer() {
- wireMockServer.start();
- configureFor("localhost", wireMockServer.port());
- }
-
- @Test
- public void shouldReturnRepositoryNameWhenAdded() {
- assertEquals(Arrays.asList(CENTRAL_REPOSITORY_NAME, localRepository.getName(),
- firstRepository.getName()),
- configuration.getRepositoriesNames());
- }
-
- @Test
- public void shouldNotAddRepositoryWhenRepositoryAlreadyExists() {
- configuration.addRepository(firstRepository.getName(), firstRepositoryURL);
- assertEquals(Arrays.asList(CENTRAL_REPOSITORY_NAME, localRepository.getName(),
- firstRepository.getName()),
- configuration.getRepositoriesNames());
- }
-
- @Test
- public void shouldDeleteRepositoryWhenDeleteAddedRepository() {
- List repositoriesNames = configuration.getRepositoriesNames();
- configuration.removeRepository(firstRepository.getName());
- assertEquals(Arrays.asList(CENTRAL_REPOSITORY_NAME,
- localRepository.getName()),
- configuration.getRepositoriesNames());
- }
-
- @Test
- public void shouldNotDeleteRepositoryWhenDeleteRepositoryNotAdded() {
- configuration.removeRepository(secondRepository.getName());
- assertEquals(Arrays.asList(CENTRAL_REPOSITORY_NAME,
- localRepository.getName(), firstRepository.getName()),
- configuration.getRepositoriesNames());
- }
-
- @Test
- public void shouldReturnOnlyRepositoriesWithInstalledTemplateWhenGetRepositoriesWithInstalledTemplates()
- throws ConfigurationException {
-
- prepareExpectedRepositoryWithInstalledTemplates();
-
- configuration.addRepository(secondRepository.getName(), secondRepositoryURL);
- configuration
- .manageTemplate(LocalConfiguration.INSTALL, firstRepository.getName(), firstTemplateID,
- firstTemplateVersion);
-
- List expected = Arrays
- .asList(localRepositoryConfiguration, repositoryWithInstalledTemplates);
-
- List actual = configuration
- .getRepositoriesWithInstalledTemplates();
-
- //We are taking the second since the first it's the default Siebel
- assertTrue(expected.size() == actual.size() && actual.get(1).equals(expected.get(1)));
- }
-
- private void prepareExpectedRepositoryWithInstalledTemplates() {
- when(repositoryWithInstalledTemplates.getName()).thenReturn(FIRST_REPO_NAME);
- when(repositoryWithInstalledTemplates.getUrl()).thenReturn(firstRepositoryURL);
- when(repositoryWithInstalledTemplates.getInstalledTemplates())
- .thenReturn(new HashMap() {{
- put(firstTemplateID, firstTemplateVersion);
+public class LocalConfigurationTest extends WiredBaseTest {
+ private static final String VERSION_ONE = "1.0";
+ private static final String DUMMY_FILE_VERSION_ONE = "dummy-1.0.jar";
+ private static final String SIEBEL_REPO_NAME = "siebel";
+ private static final String FIRST_REPO_NAME = "first";
+ private static final String TEST_REPO_NAME = "test";
+ private static final String SECOND_REPO_NAME = "second";
+ private static final String firstRepositoryURL = "localhost/firstRepository.json";
+ private static final String secondRepositoryURL = "localhost/secondRepository.json";
+ private static final String DEFAULT_ULR = "http://localhost.com/1";
+ private static final String JAR_SUFFIX = ".jar";
+ private static final String firstTemplateID = "first";
+ private static final String firstTemplateVersion = "1.0";
+ private static final String firstTemplateDescription = "Description1";
+ private static final String REPOSITORY_ID = "R1";
+ private static final String SIEBEL_ID = "siebel";
+ private static final String SIEBEL_DESCRIPTION = "This is the first version of the " + "SIEBEL CRM correlation recorder rules
" + "It contains 16 of the most used Correlations for the platform.
";
+ private static final String SIEBEL_VERSION = "1.0";
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+ public JUnitSoftAssertions softly = new JUnitSoftAssertions();
+ @Mock
+ private CorrelationTemplateDependency firstDependency;
+ @Mock
+ private CorrelationTemplatesRepository localRepository;
+ @Mock
+ private CorrelationTemplatesRepository firstRepository;
+ @Mock
+ private CorrelationTemplatesRepository secondRepository;
+ @Mock
+ private CorrelationTemplatesRepositoryConfiguration repositoryWithInstalledTemplates;
+ @Mock
+ private CorrelationTemplatesRepositoryConfiguration localRepositoryConfiguration;
+ @Mock
+ private CorrelationTemplatesRepository expectedSiebelRepository;
+ @Mock
+ private CorrelationTemplatesRepository expectedCentralRepository;
+ private LocalConfiguration configuration;
+ private String dependenciesFolder;
+ private static final String TEMPLATE_FILE_SUFFIX = "template.json";
+
+ private static final String REPOSITORY_FILE_SUFFIX = "repository.json";
+
+ private static final String LOCAL_REPOSITORY_NAME = "local";
+ private static final String LOCAL_REPOSITORY_DISPLAY_NAME = "Local";
+
+ private static final String CENTRAL_REPOSITORY_NAME = "central";
+ private static final String CENTRAL_REPOSITORY_DISPLAY_NAME = "GitHub's Central";
+
+ private static final String SIEBEL_TEMPLATE_REFERENCE_NAME = "siebel";
+ private static final String WORDPRESS_TEMPLATE_REFERENCE_NAME = "wordpress";
+ private static final String TEMPLATE_VERSION_TWO = "1.1";
+ private static final String TEMPLATE_VERSION_ONE = "1.0";
+
+ private static final String TEMPLATE_VERSION_THREE = "0.1-alpha";
+
+ private static final String CORRELATION_TEMPLATES_REPOSITORY_NAME = "CorrelationTemplatesRepository";
+
+ private static final String SIEBEL_TEMPLATE_VERSION_TWO_NAME = SIEBEL_TEMPLATE_REFERENCE_NAME + "-" + TEMPLATE_VERSION_TWO + "-" + TEMPLATE_FILE_SUFFIX;
+ private static final String SIEBEL_TEMPLATE_VERSION_ONE_NAME = SIEBEL_TEMPLATE_REFERENCE_NAME + "-" + TEMPLATE_VERSION_ONE + "-" + TEMPLATE_FILE_SUFFIX;
+
+ private static final String WORDPRESS_TEMPLATE_VERSION_ONE_NAME = WORDPRESS_TEMPLATE_REFERENCE_NAME + "-" + TEMPLATE_VERSION_ONE + "-" + TEMPLATE_FILE_SUFFIX;
+
+ @Before
+ public void setUp() throws IOException {
+ String path = folder.getRoot().getPath();
+ LocalConfiguration.installDefaultFiles(path);
+ configuration = new LocalConfiguration(path, true);
+ configuration.setupRepositoryManagers();
+ when(firstRepository.getName()).thenReturn(FIRST_REPO_NAME);
+ when(secondRepository.getName()).thenReturn(SECOND_REPO_NAME);
+ when(localRepository.getName()).thenReturn(LOCAL_REPOSITORY_NAME);
+ configuration.addRepository(firstRepository.getName(), firstRepositoryURL);
+ dependenciesFolder = folder.getRoot().getAbsolutePath() + "/lib/";
+ prepareExpectedLocalRepository();
+ }
+
+ @After
+ public void tearDown() {
+ stopWiredMock();
+ }
+
+ private void prepareExpectedLocalRepository() {
+ when(expectedSiebelRepository.getValues()).thenReturn(CORRELATION_TEMPLATES_REPOSITORY_NAME + "{name='" + LOCAL_REPOSITORY_NAME + "', displayName='" + LOCAL_REPOSITORY_DISPLAY_NAME + "', templatesVersions={" + SIEBEL_TEMPLATE_REFERENCE_NAME + "=CorrelationTemplateVersions {versions=[" + TEMPLATE_VERSION_ONE + "]}}}");
+
+ when(expectedCentralRepository.getValues()).thenReturn(CORRELATION_TEMPLATES_REPOSITORY_NAME + "{name='" + CENTRAL_REPOSITORY_NAME + "', displayName='" + CENTRAL_REPOSITORY_DISPLAY_NAME + "', templatesVersions={" + WORDPRESS_TEMPLATE_REFERENCE_NAME + "=CorrelationTemplateVersions {versions=[" + TEMPLATE_VERSION_THREE + "]}}}");
+
+ }
+
+ public void configureWireMockServer() {
+ wireMockServer.start();
+ configureFor("localhost", wireMockServer.port());
+ }
+
+ @Test
+ public void shouldReturnRepositoryNameWhenAdded() {
+ assertEquals(Arrays.asList(CENTRAL_REPOSITORY_NAME, localRepository.getName(), firstRepository.getName()), configuration.getRepositoriesNames());
+ }
+
+ @Test
+ public void shouldReturnNullWhenGetRepositoryWithANonExistingRepo() {
+ RepositoryManager repositoryManager = configuration.getRepositoryManager("fourth");
+ assertNull(repositoryManager);
+ }
+
+ @Test
+ public void shouldNotAddRepositoryWhenRepositoryAlreadyExists() {
+ configuration.addRepository(firstRepository.getName(), firstRepositoryURL);
+ assertEquals(Arrays.asList(CENTRAL_REPOSITORY_NAME, localRepository.getName(), firstRepository.getName()), configuration.getRepositoriesNames());
+ }
+
+ @Test
+ public void shouldDeleteRepositoryWhenDeleteAddedRepository() {
+ configuration.removeRepository(firstRepository.getName());
+ assertEquals(Arrays.asList(CENTRAL_REPOSITORY_NAME, localRepository.getName()), configuration.getRepositoriesNames());
+ }
+
+ @Test
+ public void shouldNotDeleteRepositoryWhenDeleteRepositoryNotAdded() {
+ configuration.removeRepository(secondRepository.getName());
+ assertEquals(Arrays.asList(CENTRAL_REPOSITORY_NAME, localRepository.getName(), firstRepository.getName()), configuration.getRepositoriesNames());
+ }
+
+ @Test
+ public void shouldReturnOnlyRepositoriesWithInstalledTemplateWhenGetRepositoriesWithInstalledTemplates() throws ConfigurationException {
+
+ prepareExpectedRepositoryWithInstalledTemplates();
+
+ configuration.addRepository(secondRepository.getName(), secondRepositoryURL);
+ configuration.manageTemplate(LocalConfiguration.INSTALL, firstRepository.getName(), firstTemplateID, firstTemplateVersion);
+
+ List expected = Arrays.asList(localRepositoryConfiguration, repositoryWithInstalledTemplates);
+
+ List actual = configuration.getRepositoriesWithInstalledTemplates();
+
+ //We are taking the second since the first it's the default Siebel
+ assertTrue(expected.size() == actual.size() && actual.get(1).equals(expected.get(1)));
+ }
+
+ private void prepareExpectedRepositoryWithInstalledTemplates() {
+ when(repositoryWithInstalledTemplates.getName()).thenReturn(FIRST_REPO_NAME);
+ when(repositoryWithInstalledTemplates.getUrl()).thenReturn(firstRepositoryURL);
+ when(repositoryWithInstalledTemplates.getInstalledTemplates()).thenReturn(new HashMap() {{
+ put(firstTemplateID, firstTemplateVersion);
}});
- }
-
- @Test
- public void shouldReturnTrueWhenIsInstalledWithInstalledTemplate() throws ConfigurationException {
- configuration
- .manageTemplate(LocalConfiguration.INSTALL, firstRepository.getName(), firstTemplateID,
- firstTemplateVersion);
- assertTrue(configuration
- .isInstalled(firstRepository.getName(), firstTemplateID, firstTemplateVersion));
- }
-
- @Test
- public void shouldReturnFalseWhenIsInstalledWithInstalledTemplate() {
- assertFalse(
- configuration
- .isInstalled(firstRepository.getName(), firstTemplateID, firstTemplateVersion));
- }
-
- @Test
- public void shouldReturnListWithRepositoriesWhenGetRepositoriesNames() {
- configuration.addRepository(secondRepository.getName(), secondRepositoryURL);
- assertEquals(Arrays.asList(CENTRAL_REPOSITORY_NAME,
- localRepository.getName(), FIRST_REPO_NAME,
- SECOND_REPO_NAME),
- configuration.getRepositoriesNames());
- }
-
- @Test
- public void shouldReturnURLWhenGetRepositoryURL() {
- assertEquals(firstRepositoryURL, configuration.getRepositoryURL(firstRepository.getName()));
- }
-
- @Test
- public void shouldInstallLocalRepositoryOnStart() {
- assertTrue(configuration.getRepositoriesWithInstalledTemplates().stream()
- .anyMatch(r -> r.getInstalledTemplates().containsKey(SIEBEL_REPO_NAME)));
- }
-
- @Test
- public void shouldDownloadDependenciesWhenDownloadDependencies()
- throws IOException, InterruptedException {
- prepareDependenciesFolder();
- createSingleDependency(1);
- buildExpectedDependencies();
- prepareMockServer();
- prepareDependency(firstDependency, mockURL("/" + DUMMY_FILE_VERSION_ONE), 1);
-
- configuration.downloadDependencies(Collections.singletonList(firstDependency));
-
- List expectedDependencies = Collections.singletonList(DUMMY_FILE_VERSION_ONE);
- List actualDependencies = getInstalledDependencies();
-
- softly.assertThat(expectedDependencies.size()).isEqualTo(actualDependencies.size());
- softly.assertThat(expectedDependencies).containsAll(actualDependencies);
- }
-
- private void prepareMockServer() throws IOException {
-
- wireMockServer.start();
- configureFor("localhost", wireMockServer.port());
- String dummyContent = "";
- try {
- dummyContent = getFileContent("/" + DUMMY_FILE_VERSION_ONE, getClass());
- } catch (Exception ex) {
- ex.printStackTrace(System.err);
- }
- mockingResponse("/" + DUMMY_FILE_VERSION_ONE, HttpURLConnection.HTTP_OK,
- dummyContent, "get");
-
- }
-
- public void mockingResponse(String URL, int status, String body, String method) {
- MappingBuilder routeMapping;
- if (method.equals("head")) {
- routeMapping = head(urlEqualTo(URL));
- } else {
- routeMapping = get(urlEqualTo(URL));
- }
-
- wireMockServer.stubFor(routeMapping.willReturn(aResponse()
- .withStatus(status)
- .withBody(body)
- .withHeader("Cache-Control", "no-cache")
- .withHeader("Content-Type", "application/json")));
- }
-
- private void prepareDependenciesFolder() {
- new File(dependenciesFolder).mkdir();
- }
-
- private void prepareDependency(CorrelationTemplateDependency dependency, String url, int count) {
- when(dependency.getName()).thenReturn("dummy");
- when(dependency.getUrl()).thenReturn(url);
- when(dependency.getVersion()).thenReturn(count + ".0");
- }
-
- private String mockURL(String resourceName) {
- return "http://localhost:" + wireMockServer.port() + resourceName;
- }
-
- private List getInstalledDependencies() {
- return Arrays.stream(Objects.requireNonNull(
- new File(dependenciesFolder).list()))
- .filter(f -> f.toLowerCase().endsWith(JAR_SUFFIX))
- .collect(Collectors.toList());
- }
-
- @Test
- public void shouldDeleteJarsWhenDeleteConflicts() throws IOException {
- prepareDependenciesFolder();
- prepareDependency(firstDependency, DEFAULT_ULR, 1);
- List conflictingDependencies = createConflictingDependencies();
-
- List previousDependencies = getInstalledDependencies();
- configuration.deleteConflicts(conflictingDependencies);
- List actualDependencies = getInstalledDependencies();
-
- softly.assertThat(previousDependencies.size()).isEqualTo(actualDependencies.size());
- softly.assertThat(actualDependencies.isEmpty()).isTrue();
- }
-
- private ArrayList createConflictingDependencies() throws IOException {
- ArrayList conflictingDependencies = new ArrayList<>();
- conflictingDependencies.add(createSingleDependency(2));
- conflictingDependencies.add(createSingleDependency(3));
- return conflictingDependencies;
- }
-
- public File createSingleDependency(int count) throws IOException {
- File dependency = new File(dependenciesFolder + "dummy-" + count + ".0" + JAR_SUFFIX);
- dependency.createNewFile();
- return dependency;
- }
-
- @Test
- public void shouldFindJarsWhenGetJarFileByConditionWithNameContains() throws IOException {
- prepareDependenciesFolder();
- createSingleDependency(1);
- assertArrayEquals(buildExpectedDependencies(), configuration
- .getJarFileByCondition(dependenciesFolder, (fileName) -> fileName.contains(VERSION_ONE)));
- }
-
- private File[] buildExpectedDependencies() {
- return new File[] {new File(dependenciesFolder + DUMMY_FILE_VERSION_ONE)};
- }
-
- @Test
- public void shouldReturnEmptyWhenHasConflictingDependenciesWithDependencyInstalled()
- throws IOException {
- prepareDependenciesFolder();
- createSingleDependency(1);
- List conflictingDependencies = createConflictingDependencies();
- prepareDependency(firstDependency, DEFAULT_ULR, 1);
- assertNotEquals(
- configuration.findConflictingDependencies(Collections.singletonList(firstDependency)),
- conflictingDependencies);
- }
-
- @Test
- public void shouldReturnConflictingFilesWhenFindConflictingDependenciesWithDifferentJarsVersions()
- throws IOException {
- prepareDependenciesFolder();
- List conflictingDependencies = createConflictingDependencies();
- prepareDependency(firstDependency, DEFAULT_ULR, 1);
- assert (configuration.findConflictingDependencies(Collections.singletonList(firstDependency))
- .containsAll(conflictingDependencies));
- }
-
- @Test
- public void shouldReturnFalseWhenHasConflictingDependenciesWithDifferentJarsVersions() {
- prepareDependenciesFolder();
- prepareDependency(firstDependency, DEFAULT_ULR, 1);
- assert (configuration.findConflictingDependencies(Collections.singletonList(firstDependency))
- .isEmpty());
- }
-
- @Test
- public void shouldReturnErrorWhenCheckRepositoryUrlWithUrlWithoutProtocol() {
- String repositoryURL = "test.com/firstRepository.json";
- List errors = configuration.checkRepositoryURL(REPOSITORY_ID, repositoryURL);
- assertEquals(Collections.singletonList(
- "- We couldn't parse " + REPOSITORY_ID + "'s url " + repositoryURL
- + ".\n Error: no protocol: test.com/firstRepository.json"), errors);
- }
-
- @Test
- public void shouldReturnErrorWhenCheckRepositoryURlWithUrlWithNotFoundError() {
- configureWireMockServer();
- String path = "/firstRepository.json";
- String url = getBaseURL() + path;
- mockingResponse(path, HttpURLConnection.HTTP_NOT_FOUND, "", "head");
-
- List errors = configuration.checkRepositoryURL(REPOSITORY_ID, url);
- assertEquals(Collections.singletonList(
- "- We couldn't reach " + REPOSITORY_ID + "'s url " + url
- + ".\n Error: 404: Not Found"), errors);
- }
-
- private String getBaseURL() {
- return "http://localhost:" + wireMockServer.port();
- }
-
- @Test
- public void shouldReturnErrorWhenCheckRepositoryURlWithNotExistentLocalUrl() {
- String repositoryURL = "file://C:/test/firstRepository.json";
- List errors = configuration.checkRepositoryURL(REPOSITORY_ID, repositoryURL);
- assertEquals(Collections.singletonList(
- "- We couldn't reach " + REPOSITORY_ID + "'s Path " + repositoryURL + ".\n"
- + " Error: File doesn't exist"), errors);
- }
-
- @Test
- public void shouldReturnErrorWhenCheckRepositoryURlWithNoJsonFile() {
- String repositoryURL = "file://C:/test/";
- List errors = configuration.checkRepositoryURL(REPOSITORY_ID, repositoryURL);
- assertEquals(Collections.singletonList(
- "- There was and error on the repository " + REPOSITORY_ID + "'s URL " + repositoryURL +
- ".\n"
- + " Error: URL should lead to .json file"), errors);
- }
-
- @Test
- public void shouldReturnLocalCorrelationTemplatesRepositoriesWhenGetRepositories() {
- assertEquals(getRepositoriesNames(prepareExpectedLocalRepositories()),
- getRepositoriesNames(configuration.getRepositories()));
- }
-
- private List getRepositoriesNames(List repositories) {
- return repositories.stream().map(CorrelationTemplatesRepository::getValues)
- .collect(Collectors.toList());
- }
-
- private List prepareExpectedLocalRepositories() {
- List expectedLocalRepositories = new ArrayList<>();
- expectedLocalRepositories.add(expectedCentralRepository);
- expectedLocalRepositories.add(expectedSiebelRepository);
-
- return expectedLocalRepositories;
- }
+ }
+
+ @Test
+ public void shouldReturnTrueWhenIsInstalledWithInstalledTemplate() throws ConfigurationException {
+ configuration.manageTemplate(LocalConfiguration.INSTALL, firstRepository.getName(), firstTemplateID, firstTemplateVersion);
+ assertTrue(configuration.isInstalled(firstRepository.getName(), firstTemplateID, firstTemplateVersion));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenIsInstalledWithNotInstalledTemplate() {
+ assertFalse(configuration.isInstalled(firstRepository.getName(), firstTemplateID, firstTemplateVersion));
+ }
+
+ @Test(expected = ConfigurationException.class)
+ public void shouldThrowAnExceptionWhenManageTemplateWithNotAddedRepo() throws ConfigurationException {
+ configuration.manageTemplate(LocalConfiguration.INSTALL, secondRepository.getName(), firstTemplateID, firstTemplateVersion);
+ }
+
+ @Test
+ public void shouldUninstallTemplateWhenManageTemplateWithEmptyAction() throws ConfigurationException {
+ configuration.manageTemplate(LocalConfiguration.INSTALL, firstRepository.getName(), firstTemplateID, firstTemplateVersion);
+
+ configuration.manageTemplate("", firstRepository.getName(), firstTemplateID, firstTemplateVersion);
+ assertFalse(configuration.isInstalled(firstRepository.getName(), firstTemplateID, firstTemplateVersion));
+ }
+
+ @Test
+ public void shouldInstallTemplateWhenInstallTemplate() throws ConfigurationException, IOException {
+ prepareRepoFiles();
+ configuration.installTemplate(TEST_REPO_NAME, firstTemplateID, firstTemplateVersion);
+ assertTrue(configuration.isInstalled(TEST_REPO_NAME, firstTemplateID, firstTemplateVersion));
+ }
+
+ private void prepareRepoFiles() throws IOException {
+ removeCentralRepo();
+ startWiredMock(WIRED_HOST);
+ RemoteUrlRepository testRepo = createRemoteRepository();
+ mockRequestsToRepoFiles();
+ addAndInstallRepos(testRepo);
+ }
+
+ private void addAndInstallRepos(RemoteRepository testRepo) {
+ configuration.addRepositoryManager(testRepo);
+ configuration.setupRepositoryManagers();
+ }
+
+ private void removeCentralRepo() {
+ configuration.getRepositoriesManagers().remove(CENTRAL_REPOSITORY_NAME);
+ configuration.removeRepository(CENTRAL_REPOSITORY_NAME);
+ }
+
+ private RemoteUrlRepository createRemoteRepository() {
+ RemoteUrlRepository testRepo = new RemoteUrlRepository();
+ testRepo.setName(TEST_REPO_NAME);
+ testRepo.setEndPoint(getBaseURL() + TEST_REPOSITORY_URL);
+ testRepo.setConfig(configuration);
+ testRepo.init();
+ return testRepo;
+ }
+
+ @Test
+ public void shouldUninstallTemplateWhenUninstallTemplate() throws ConfigurationException {
+ configuration.manageTemplate(LocalConfiguration.INSTALL, firstRepository.getName(), firstTemplateID, firstTemplateVersion);
+ configuration.uninstallTemplate(firstRepository.getName(), firstTemplateID, firstTemplateVersion);
+ assertFalse(configuration.isInstalled(firstRepository.getName(), firstTemplateID, firstTemplateVersion));
+ }
+
+ @Test
+ public void shouldReturnListWithRepositoriesWhenGetRepositoriesNames() {
+ configuration.addRepository(secondRepository.getName(), secondRepositoryURL);
+ assertEquals(Arrays.asList(CENTRAL_REPOSITORY_NAME, localRepository.getName(), FIRST_REPO_NAME, SECOND_REPO_NAME), configuration.getRepositoriesNames());
+ }
+
+ @Test
+ public void shouldReturnURLWhenGetRepositoryURL() {
+ assertEquals(firstRepositoryURL, configuration.getRepositoryURL(firstRepository.getName()));
+ }
+
+ @Test
+ public void shouldReturnTrueWhenRefreshRepositoryWithUpToDataRemoteRepoAndLocal() throws IOException, ConfigurationException {
+ prepareRepoFiles();
+ List progressList = new ArrayList<>();
+ Consumer progressConsumer = progressList::add;
+
+ List statusList = new ArrayList<>();
+ Consumer statusConsumer = statusList::add;
+ Assert.assertTrue(configuration.refreshRepositories("", progressConsumer, statusConsumer));
+
+ assertEquals(Arrays.asList(0, 25, 50, 75, 100, 100), progressList);
+ assertEquals(Arrays.asList("Syncing 'test' repository.", "Syncing 'local' repository.", "Updating 'Local' repository.", "Updating 'http://localhost:" + getWiredPort() + TEST_REPOSITORY_URL + "' repository.", "Update finished"), statusList);
+ }
+
+ @Test
+ public void shouldReturnInstalledTemplatesWhenGetInstalledTemplates() {
+ List installedTemplates = configuration.getInstalledTemplates();
+ Assert.assertEquals(installedTemplates.get(0).getId(), SIEBEL_ID);
+ Assert.assertEquals(installedTemplates.get(0).getDescription(), SIEBEL_DESCRIPTION);
+ Assert.assertEquals(installedTemplates.get(0).getVersion(), SIEBEL_VERSION);
+ }
+
+ @Test
+ public void shouldReturnTrueWhenIsValidDependenciyURLWithValidURL() throws IOException {
+ startWiredMock(WIRED_HOST);
+ mockingResponse(TEST_REPOSITORY_URL, 200, TestUtils.getFileContent(TEST_REPOSITORY_URL, getClass()), "head");
+ boolean isValid = configuration.isValidDependencyURL(getBaseURL() + TEST_REPOSITORY_URL, TEST_REPO_NAME, "1.0");
+ Assert.assertTrue(isValid);
+ }
+
+ @Test
+ public void shouldReturnFileNameForTemplateWhenGetTemplateFilename() {
+ Template siebel = configuration.getInstalledTemplates().get(0);
+ String fileName = LocalConfiguration.getTemplateFilename(siebel);
+ Assert.assertEquals(SIEBEL_ID + "-" + SIEBEL_VERSION + "-template.json", fileName);
+ }
+
+ @Test
+ public void shouldReturnRepoFolderWhenGetRepositoryFolder() throws IOException {
+ prepareRepoFiles();
+ File repoFolder = configuration.getRepositoryFolder(TEST_REPO_NAME);
+ Assert.assertEquals(Paths.get(folder.getRoot().getPath(), "correlation-templates", TEST_REPO_NAME).toAbsolutePath().toString(), repoFolder.getAbsolutePath());
+ }
+
+ @Test
+ public void shouldReadTemplatePropertiesWhenReadTemplatePropertiesFromPath() throws IOException {
+ prepareRepoFiles();
+ Path templatePath = Paths.get(folder.getRoot().getPath(), "correlation-templates", TEST_REPO_NAME, firstTemplateID + "-" + firstTemplateVersion + "-properties.json");
+ TemplateProperties templateprop = configuration.readTemplatePropertiesFromPath(templatePath.toAbsolutePath().toString());
+ Assert.assertEquals("false", templateprop.get("not_allow_export"));
+ Assert.assertEquals("false", templateprop.get("disallow_to_use"));
+ }
+
+ @Test
+ public void shouldReadTemplateCorrectlyWhenReadTemplateFromString() throws IOException {
+ prepareRepoFiles();
+ String templateString = TestUtils.getFileContent(FIRST_1_0_TEMPLATE_URL, getClass());
+ Template template = configuration.readTemplateFromString(templateString);
+ Assert.assertEquals(firstTemplateID + "-" + firstTemplateVersion, template.getId());
+ Assert.assertEquals(firstTemplateDescription, template.getDescription());
+ Assert.assertEquals(firstTemplateVersion, template.getVersion());
+ Assert.assertEquals(0, template.getRules().size());
+ }
+
+ @Test
+ public void shouldInstallLocalRepositoryOnStart() {
+ assertTrue(configuration.getRepositoriesWithInstalledTemplates().stream().anyMatch(r -> r.getInstalledTemplates().containsKey(SIEBEL_REPO_NAME)));
+ }
+
+ @Test
+ public void shouldDownloadDependenciesWhenDownloadDependencies() throws IOException, InterruptedException {
+ prepareDependenciesFolder();
+ createSingleDependency(1);
+ buildExpectedDependencies();
+ prepareMockServer();
+ prepareDependency(firstDependency, mockURL("/" + DUMMY_FILE_VERSION_ONE), 1);
+
+ configuration.downloadDependencies(Collections.singletonList(firstDependency));
+
+ List expectedDependencies = Collections.singletonList(DUMMY_FILE_VERSION_ONE);
+ List actualDependencies = getInstalledDependencies();
+
+ softly.assertThat(expectedDependencies.size()).isEqualTo(actualDependencies.size());
+ softly.assertThat(expectedDependencies).containsAll(actualDependencies);
+ }
+
+ private void prepareMockServer() throws IOException {
+
+ wireMockServer.start();
+ configureFor("localhost", wireMockServer.port());
+ String dummyContent = "";
+ try {
+ dummyContent = getFileContent("/" + DUMMY_FILE_VERSION_ONE, getClass());
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ }
+ mockingResponse("/" + DUMMY_FILE_VERSION_ONE, HttpURLConnection.HTTP_OK, dummyContent, "get");
+
+ }
+
+ private void prepareDependenciesFolder() {
+ new File(dependenciesFolder).mkdir();
+ }
+
+ private void prepareDependency(CorrelationTemplateDependency dependency, String url, int count) {
+ when(dependency.getName()).thenReturn("dummy");
+ when(dependency.getUrl()).thenReturn(url);
+ when(dependency.getVersion()).thenReturn(count + ".0");
+ }
+
+ private String mockURL(String resourceName) {
+ return "http://localhost:" + wireMockServer.port() + resourceName;
+ }
+
+ private List getInstalledDependencies() {
+ return Arrays.stream(Objects.requireNonNull(new File(dependenciesFolder).list())).filter(f -> f.toLowerCase().endsWith(JAR_SUFFIX)).collect(Collectors.toList());
+ }
+
+ @Test
+ public void shouldDeleteJarsWhenDeleteConflicts() throws IOException {
+ prepareDependenciesFolder();
+ prepareDependency(firstDependency, DEFAULT_ULR, 1);
+ List conflictingDependencies = createConflictingDependencies();
+
+ List previousDependencies = getInstalledDependencies();
+ configuration.deleteConflicts(conflictingDependencies);
+ List actualDependencies = getInstalledDependencies();
+
+ softly.assertThat(previousDependencies.size()).isEqualTo(actualDependencies.size());
+ softly.assertThat(actualDependencies.isEmpty()).isTrue();
+ }
+
+ private ArrayList createConflictingDependencies() throws IOException {
+ ArrayList conflictingDependencies = new ArrayList<>();
+ conflictingDependencies.add(createSingleDependency(2));
+ conflictingDependencies.add(createSingleDependency(3));
+ return conflictingDependencies;
+ }
+
+ public File createSingleDependency(int count) throws IOException {
+ File dependency = new File(dependenciesFolder + "dummy-" + count + ".0" + JAR_SUFFIX);
+ dependency.createNewFile();
+ return dependency;
+ }
+
+ @Test
+ public void shouldFindJarsWhenGetJarFileByConditionWithNameContains() throws IOException {
+ prepareDependenciesFolder();
+ createSingleDependency(1);
+ assertArrayEquals(buildExpectedDependencies(), configuration.getJarFileByCondition(dependenciesFolder, (fileName) -> fileName.contains(VERSION_ONE)));
+ }
+
+ private File[] buildExpectedDependencies() {
+ return new File[]{new File(dependenciesFolder + DUMMY_FILE_VERSION_ONE)};
+ }
+
+ @Test
+ public void shouldReturnEmptyWhenHasConflictingDependenciesWithDependencyInstalled() throws IOException {
+ prepareDependenciesFolder();
+ createSingleDependency(1);
+ List conflictingDependencies = createConflictingDependencies();
+ prepareDependency(firstDependency, DEFAULT_ULR, 1);
+ assertNotEquals(configuration.findConflictingDependencies(Collections.singletonList(firstDependency)), conflictingDependencies);
+ }
+
+ @Test
+ public void shouldReturnConflictingFilesWhenFindConflictingDependenciesWithDifferentJarsVersions() throws IOException {
+ prepareDependenciesFolder();
+ List conflictingDependencies = createConflictingDependencies();
+ prepareDependency(firstDependency, DEFAULT_ULR, 1);
+ assert (configuration.findConflictingDependencies(Collections.singletonList(firstDependency)).containsAll(conflictingDependencies));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenHasConflictingDependenciesWithDifferentJarsVersions() {
+ prepareDependenciesFolder();
+ prepareDependency(firstDependency, DEFAULT_ULR, 1);
+ assert (configuration.findConflictingDependencies(Collections.singletonList(firstDependency)).isEmpty());
+ }
+
+ @Test
+ public void shouldReturnErrorWhenCheckRepositoryUrlWithUrlWithoutProtocol() {
+ String repositoryURL = "test.com/firstRepository.json";
+ List errors = configuration.checkRepositoryURL(REPOSITORY_ID, repositoryURL);
+ assertEquals(Collections.singletonList("- We couldn't parse " + REPOSITORY_ID + "'s url " + repositoryURL + ".\n Error: no protocol: test.com/firstRepository.json"), errors);
+ }
+
+ @Test
+ public void shouldReturnErrorWhenCheckRepositoryURlWithUrlWithNotFoundError() {
+ configureWireMockServer();
+ String path = "/firstRepository.json";
+ String url = getBaseURL() + path;
+ mockingResponse(path, HttpURLConnection.HTTP_NOT_FOUND, "", "head");
+
+ List errors = configuration.checkRepositoryURL(REPOSITORY_ID, url);
+ assertEquals(Collections.singletonList("- We couldn't reach " + REPOSITORY_ID + "'s url " + url + ".\n Error: 404: Not Found"), errors);
+ }
+
+ @Test
+ public void shouldReturnErrorWhenCheckRepositoryURlWithNotExistentLocalUrl() {
+ String repositoryURL = "file://C:/test/firstRepository.json";
+ List errors = configuration.checkRepositoryURL(REPOSITORY_ID, repositoryURL);
+ assertEquals(Collections.singletonList("- We couldn't reach " + REPOSITORY_ID + "'s Path " + repositoryURL + ".\n" + " Error: File doesn't exist"), errors);
+ }
+
+ @Test
+ public void shouldReturnErrorWhenCheckRepositoryURlWithNoJsonFile() {
+ String repositoryURL = "file://C:/test/";
+ List errors = configuration.checkRepositoryURL(REPOSITORY_ID, repositoryURL);
+ assertEquals(Collections.singletonList("- There was and error on the repository " + REPOSITORY_ID + "'s URL " + repositoryURL + ".\n" + " Error: URL should lead to .json file"), errors);
+ }
+
+ @Test
+ public void shouldReturnLocalCorrelationTemplatesRepositoriesWhenGetRepositories() {
+ assertEquals(getRepositoriesNames(prepareExpectedLocalRepositories()), getRepositoriesNames(configuration.getRepositories()));
+ }
+
+ private List getRepositoriesNames(List repositories) {
+ return repositories.stream().map(CorrelationTemplatesRepository::getValues).collect(Collectors.toList());
+ }
+
+ private List prepareExpectedLocalRepositories() {
+ List expectedLocalRepositories = new ArrayList<>();
+ expectedLocalRepositories.add(expectedCentralRepository);
+ expectedLocalRepositories.add(expectedSiebelRepository);
+
+ return expectedLocalRepositories;
+ }
}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/LocalCorrelationTemplatesRegistryTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/LocalCorrelationTemplatesRegistryTest.java
index e3201cc..2b57edd 100644
--- a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/LocalCorrelationTemplatesRegistryTest.java
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/LocalCorrelationTemplatesRegistryTest.java
@@ -12,15 +12,26 @@
import com.blazemeter.jmeter.correlation.core.extractors.ResultField;
import com.blazemeter.jmeter.correlation.core.replacements.RegexCorrelationReplacement;
import com.blazemeter.jmeter.correlation.core.templates.Template.Builder;
+import com.blazemeter.jmeter.correlation.core.templates.repository.RepositoryManager;
+import com.blazemeter.jmeter.correlation.core.templates.repository.TemplateProperties;
+import com.blazemeter.jmeter.correlation.core.templates.repository.pluggable.LocalRepository;
import com.google.common.io.Resources;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Paths;
+import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -51,7 +62,7 @@ public class LocalCorrelationTemplatesRegistryTest {
@Mock
private CorrelationEngine correlationEngine;
private CorrelationProxyControl proxyControl;
-
+ private LocalConfiguration configuration;
@BeforeClass
public static void setupClass() {
JMeterTestUtils.setupJmeterEnv();
@@ -60,7 +71,7 @@ public static void setupClass() {
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
- LocalConfiguration configuration = new LocalConfiguration(folder.getRoot().getPath(), true);
+ configuration = new LocalConfiguration(folder.getRoot().getPath(), true);
CorrelationProxyControlBuilder builder = new CorrelationProxyControlBuilder();
builder.withCorrelationEngine(correlationEngine)
.withCorrelationTemplatesRegistry(new LocalCorrelationTemplatesRegistry(configuration))
@@ -173,4 +184,53 @@ public void shouldGenerateJSONWhenOnSaveWithDependencies()
compareWithoutSpaces(expected, actual);
}
+
+ @Test
+ public void shouldReturnTemplatesAndPropertiesWhenGetCorrelationTemplatesAndPropertiesByRepositoryId(){
+ String path = folder.getRoot().getPath();
+ LocalConfiguration.installDefaultFiles(path);
+ configuration.setupRepositoryManagers();
+ LocalCorrelationTemplatesRepositoriesRegistry localCorrelationTemplatesRepoReg = new LocalCorrelationTemplatesRepositoriesRegistry(configuration);
+ Map templatePropertiesMap = localCorrelationTemplatesRepoReg.getCorrelationTemplatesAndPropertiesByRepositoryId("local");
+ Map.Entry entire = templatePropertiesMap.entrySet().iterator().next();
+ Assert.assertEquals("false",entire.getValue().get("not_allow_export"));
+ Assert.assertEquals("false",entire.getValue().get("disallow_to_use"));
+ Assert.assertEquals("siebel",entire.getKey().getId());
+ }
+
+ @Test
+ public void shouldReturnTemplatesAndPropertiesWhenGetCorrelationTemplatesAndPropertiesByRepositoryIdWhitFilter(){
+ String path = folder.getRoot().getPath();
+ LocalConfiguration.installDefaultFiles(path);
+ configuration.setupRepositoryManagers();
+ LocalCorrelationTemplatesRepositoriesRegistry localCorrelationTemplatesRepoReg = new LocalCorrelationTemplatesRepositoriesRegistry(configuration);
+ List filter = new ArrayList<>();
+ filter.add(new TemplateVersion("siebel", "1.0"));
+ Map templatePropertiesMap =
+ localCorrelationTemplatesRepoReg.getCorrelationTemplatesAndPropertiesByRepositoryId("local", filter );
+ Map.Entry entire = templatePropertiesMap.entrySet().iterator().next();
+ Assert.assertEquals("false",entire.getValue().get("not_allow_export"));
+ Assert.assertEquals("false",entire.getValue().get("disallow_to_use"));
+ Assert.assertEquals("siebel",entire.getKey().getId());
+ }
+
+ @Test
+ public void shouldReturnTemplateVersionsWhenGetCorrelationTemplateVersionsByRepositoryId(){
+ String path = folder.getRoot().getPath();
+ LocalConfiguration.installDefaultFiles(path);
+ configuration.setupRepositoryManagers();
+ LocalCorrelationTemplatesRepositoriesRegistry localCorrelationTemplatesRepoReg = new LocalCorrelationTemplatesRepositoriesRegistry(configuration);
+ Map correlationTemplateVersionsMap =
+ localCorrelationTemplatesRepoReg.getCorrelationTemplateVersionsByRepositoryId("local");
+ Assert.assertEquals("local",correlationTemplateVersionsMap.get("siebel").getRepositoryDisplayName());
+ Assert.assertEquals("1.0",correlationTemplateVersionsMap.get("siebel").getVersions().get(0));
+ }
+ @Test
+ public void shouldReturnTrueWhenIsLocalTemplateVersionSavedWhitSavedTemplate(){
+ String path = folder.getRoot().getPath();
+ LocalConfiguration.installDefaultFiles(path);
+ configuration.setupRepositoryManagers();
+ LocalCorrelationTemplatesRepositoriesRegistry localCorrelationTemplatesRepoReg = new LocalCorrelationTemplatesRepositoriesRegistry(configuration);
+ Assert.assertTrue(localCorrelationTemplatesRepoReg.isLocalTemplateVersionSaved("siebel", "1.0"));
+ }
}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/ProtocolTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/ProtocolTest.java
new file mode 100644
index 0000000..e24126c
--- /dev/null
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/ProtocolTest.java
@@ -0,0 +1,52 @@
+package com.blazemeter.jmeter.correlation.core.templates;
+
+import com.blazemeter.jmeter.correlation.core.templates.repository.TemplateProperties;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+public class ProtocolTest {
+
+ private static final String PROTOCOL_NAME = "Test";
+ private static final String SIEBEL_TEMPLATE_REFERENCE_NAME = "siebel";
+ private static final String TEMPLATE_VERSION_ONE = "1.0";
+ private static final String TEMPLATE_FILE_SUFFIX = "template.json";
+ private static final String SIEBEL_TEMPLATE_VERSION_ONE_NAME = SIEBEL_TEMPLATE_REFERENCE_NAME + "-" + TEMPLATE_VERSION_ONE + "-" + TEMPLATE_FILE_SUFFIX;
+
+ @Test
+ public void shouldSetTemplatesAndPropertiesWhenSetTemplatesAndProperties() {
+ TemplateProperties templateProperties = new TemplateProperties();
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME).withVersion(TEMPLATE_VERSION_ONE);
+ Template template = builder.build();
+ Protocol protocol = new Protocol(PROTOCOL_NAME);
+ Map templatesAndProperties = new HashMap<>();
+ templatesAndProperties.put(template,templateProperties);
+ protocol.setTemplatesAndProperties(templatesAndProperties);
+ assertEquals(templatesAndProperties, protocol.getTemplatesAndProperties());
+ }
+
+ @Test
+ public void shouldAddTemplateAndPropertyWhenAddTemplate() {
+ TemplateProperties templateProperties = new TemplateProperties();
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME).withVersion(TEMPLATE_VERSION_ONE);
+ Template template = builder.build();
+ Protocol protocol = new Protocol(PROTOCOL_NAME);
+ protocol.addTemplate(template, templateProperties);
+ Map templatesAndProperties = protocol.getTemplatesAndProperties();
+ Map.Entry entry = templatesAndProperties.entrySet().iterator().next();
+ assertEquals(template, entry.getKey());
+ assertEquals(templateProperties, entry.getValue());
+ }
+
+ @Test
+ public void shouldSetNameWhenSetName() {
+ Protocol protocol = new Protocol("");
+ protocol.setName(PROTOCOL_NAME);
+ assertEquals(PROTOCOL_NAME, protocol.getName());
+ }
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/RemoteCorrelationTemplatesRepositoriesRegistryTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/RemoteCorrelationTemplatesRepositoriesRegistryTest.java
index f5f97f7..a1d10d8 100644
--- a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/RemoteCorrelationTemplatesRepositoriesRegistryTest.java
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/RemoteCorrelationTemplatesRepositoriesRegistryTest.java
@@ -1,14 +1,9 @@
package com.blazemeter.jmeter.correlation.core.templates;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
-import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
-import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
-import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.junit.Assert.assertTrue;
-import com.blazemeter.jmeter.correlation.TestUtils;
-import com.github.tomakehurst.wiremock.WireMockServer;
+
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
@@ -22,14 +17,13 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-public class RemoteCorrelationTemplatesRepositoriesRegistryTest {
+public class RemoteCorrelationTemplatesRepositoriesRegistryTest extends WiredBaseTest{
private static final String TEMPLATES_FOLDER = "correlation-templates";
+ private static final String WIRED_HOST = "localhost";
private static final String REPOSITORY_NAME = "base";
@Rule
public TemporaryFolder folder = new TemporaryFolder();
- private final WireMockServer wireMockServer = new WireMockServer(wireMockConfig().dynamicPort());
-
private RemoteCorrelationTemplatesRepositoriesRegistry remote;
@@ -38,28 +32,18 @@ public void setup() {
remote = new RemoteCorrelationTemplatesRepositoriesRegistry(
new LocalConfiguration(
Paths.get(folder.getRoot().getPath(), File.separator).toAbsolutePath().toString()));
- wireMockServer.start();
- configureFor("localhost", wireMockServer.port());
+ startWiredMock("localhost");
}
@After
public void tearDown() {
- if (wireMockServer.isRunning()) {
- wireMockServer.stop();
- }
+ stopWiredMock();
}
@Test
public void shouldSaveTemplatesAndRepositoryFromURL() throws IOException, InterruptedException {
- prepareURL("/test-repository.json");
- prepareURL("/first-1.0-template.json");
- skipURL("/first-1.0-snapshot.png");
- prepareURL("/first-1.1-template.json");
- skipURL("/first-1.1-snapshot.png");
- prepareURL("/second-1.0-template.json");
- skipURL("/second-1.0-snapshot.png");
-
- remote.save(REPOSITORY_NAME, getBaseURL() + "/test-repository.json");
+ mockRequestsToRepoFiles();
+ remote.save(REPOSITORY_NAME, getBaseURL() + TEST_REPOSITORY_URL);
List expectedFiles = Arrays
.asList("first-1.0-template.json", "base-repository.json", "second-1.0-template.json",
@@ -76,25 +60,6 @@ private void assertGeneratedFiles(List expectedFiles, List actua
expectedFiles.containsAll(actualFiles) && actualFiles.containsAll(expectedFiles));
}
- private void prepareURL(String URL) throws IOException {
- wireMockServer.stubFor(get(urlEqualTo(URL)).willReturn(aResponse()
- .withStatus(200)
- .withHeader("Cache-Control", "no-cache")
- .withHeader("Content-Type", "application/json")
- .withBody(TestUtils.getFileContent(URL, getClass()))
- ));
- }
-
- private void skipURL(String URL) {
- stubFor(get(urlEqualTo(URL)).willReturn(aResponse()
- .withStatus(304)
- ));
- }
-
- private String getBaseURL() {
- return "http://localhost:" + wireMockServer.port();
- }
-
private List getGeneratedFilesNames() {
return Arrays.stream(Objects.requireNonNull(
new File(Paths.get(
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/RepositoryTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/RepositoryTest.java
new file mode 100644
index 0000000..1dfa5cc
--- /dev/null
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/RepositoryTest.java
@@ -0,0 +1,17 @@
+package com.blazemeter.jmeter.correlation.core.templates;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class RepositoryTest {
+
+ private static final String REPOSITORY_NAME = "Test";
+
+ @Test
+ public void shouldCreateRepositoryWithNameWhenRepository() {
+ Repository repo = new Repository(REPOSITORY_NAME);
+ assertEquals(REPOSITORY_NAME, repo.getName());
+ }
+
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/TemplateTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/TemplateTest.java
new file mode 100644
index 0000000..7a42ecc
--- /dev/null
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/TemplateTest.java
@@ -0,0 +1,609 @@
+
+package com.blazemeter.jmeter.correlation.core.templates;
+
+import com.blazemeter.jmeter.correlation.core.RulesGroup;
+import com.blazemeter.jmeter.correlation.core.templates.repository.TemplateProperties;
+import org.apache.logging.log4j.core.util.Assert;
+import org.junit.Test;
+
+import java.awt.image.BufferedImage;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static java.awt.image.BufferedImage.TYPE_INT_RGB;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class TemplateTest {
+
+ private static final String BUILD_DESCRIPTION = "Description test";
+ private static final String BUILD_COMPONENT = "Component";
+ private static final String BUILD_RESPONSE_FILTERS = "responseFilters";
+ private static final String BUILD_REPOSITORY_ID = "repositoryId";
+ private static final String BUILD_CHANGES = "changes";
+ private static final String BUILD_AUTHOR = "Author";
+ private static final String BUILD_URL = "URL";
+ private static final String TEMPLATE_TYPE = "correlation";
+ private static final String SIEBEL_TEMPLATE_REFERENCE_NAME = "siebel";
+ private static final String TEMPLATE_VERSION_ONE = "1.0";
+
+
+ @Test
+ public void shouldReturnTrueWhenBuildersAreTheSameObject() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME).withVersion(TEMPLATE_VERSION_ONE);
+ assertTrue(builder.equals(builder));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenBuildersIsCompareWithObjectOfDifferentClass() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME).withVersion(TEMPLATE_VERSION_ONE);
+ assertFalse(builder.equals("aa"));
+ }
+
+ @Test
+ public void shouldReturnAStringWhenToString() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ String expectedString = "Builder{"
+ + "description='Description test', "
+ + "id='siebel', "
+ + "author='Author', "
+ + "url='URL', "
+ + "rules=[], "
+ + "responseFilters='responseFilters', "
+ + "components='Component', "
+ + "version='1.0', "
+ + "repositoryId='repositoryId', "
+ + "changes='changes'}";
+ assertEquals(builder.toString(), expectedString);
+ }
+
+ @Test
+ public void shouldReturnTrueWhenEqualsWithEqualObjects() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template.Builder builder2 = new Template.Builder();
+ builder2.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertTrue(builder.equals(builder2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDiffUrl() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template.Builder builder2 = new Template.Builder();
+ builder2.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl("BUILD_URL");
+ assertFalse(builder.equals(builder2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDiffAuthor() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template.Builder builder2 = new Template.Builder();
+ builder2.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor("BUILD_AUTHOR")
+ .withUrl(BUILD_URL);
+ assertFalse(builder.equals(builder2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDiffDependencies() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template.Builder builder2 = new Template.Builder();
+ builder2.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(null)
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertFalse(builder.equals(builder2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDiffChanges() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template.Builder builder2 = new Template.Builder();
+ builder2.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges("BUILD_CHANGES")
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertFalse(builder.equals(builder2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDiffVersion() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template.Builder builder2 = new Template.Builder();
+ builder2.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+ .withVersion("BUILD_VERSION")
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertFalse(builder.equals(builder2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDiffRepoId() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template.Builder builder2 = new Template.Builder();
+ builder2.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId("BUILD_REPOSITORY_ID")
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertFalse(builder.equals(builder2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDiffFilters() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template.Builder builder2 = new Template.Builder();
+ builder2.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters("BUILD_RESPONSE_FILTERS")
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertFalse(builder.equals(builder2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDiffComponent() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template.Builder builder2 = new Template.Builder();
+ builder2.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents("BUILD_COMPONENT")
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertFalse(builder.equals(builder2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDiffGroups() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template.Builder builder2 = new Template.Builder();
+ builder2.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(null)
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertFalse(builder.equals(builder2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDiffDescription() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template.Builder builder2 = new Template.Builder();
+ builder2.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription("BUILD_DESCRIPTION")
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertFalse(builder.equals(builder2));
+ }
+
+ @Test
+ public void shouldReturnFalseWhenEqualsWithDiffName() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId("SIEBEL_TEMPLATE_REFERENCE_NAME")
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template.Builder builder2 = new Template.Builder();
+ builder2.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertFalse(builder.equals(builder2));
+ }
+
+ @Test
+ public void shouldReturnTemplateVersionWhenToTemplateVersion() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ TemplateVersion templateVersion = builder.build().toTemplateVersion();
+ assertEquals(SIEBEL_TEMPLATE_REFERENCE_NAME, templateVersion.getName());
+ assertEquals(TEMPLATE_VERSION_ONE, templateVersion.getVersion());
+ }
+
+ @Test
+ public void shouldReturnDependenciesWhenGetDependencies() {
+ List expectedDependencies = new ArrayList<>();
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(expectedDependencies)
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertEquals(expectedDependencies, builder.build().getDependencies());
+ }
+
+ @Test
+ public void shouldReturnTypeWhenGetType() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertEquals(TEMPLATE_TYPE, builder.build().getType());
+ }
+
+ @Test
+ public void shouldReturnChangesWhenGetChanges() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ assertEquals(BUILD_CHANGES, builder.build().getChanges());
+ }
+
+ @Test
+ public void shouldSetTypeWhenSetType() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ Template template = builder.build();
+ template.setType(TEMPLATE_TYPE+ "Edited");
+ assertEquals(TEMPLATE_TYPE+ "Edited", template.getType());
+ }
+
+ @Test
+ public void shouldReturnStringWhenToString() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withGroups(new ArrayList<>())
+ .withSnapshot(new BufferedImage(300, 300, TYPE_INT_RGB))
+ .withComponents(BUILD_COMPONENT)
+ .withResponseFilters(BUILD_RESPONSE_FILTERS)
+ .withRepositoryId(BUILD_REPOSITORY_ID)
+ .withChanges(BUILD_CHANGES)
+ .withDependencies(new ArrayList<>())
+ .withAuthor(BUILD_AUTHOR)
+ .withUrl(BUILD_URL);
+ String expectedString = "CorrelationTemplate{id='siebel', "+
+ "description='Description test', "+
+ "version='1.0', "+
+ "author='Author', "+
+ "url='URL', "+
+ "components='Component', "+
+ "responseFilters='responseFilters', "+
+ "groups=[], "+
+ "dependencies=[], "+
+ "repositoryId='repositoryId', "+
+ "changes='changes', "+
+ "snapshotPath='null', "+
+ "isInstalled=false}";
+ assertEquals(expectedString, builder.build().toString());
+ }
+
+ @Test
+ public void shouldReturnHashCodeWhenHasHash() {
+ Template.Builder builder = new Template.Builder();
+ builder.withId(SIEBEL_TEMPLATE_REFERENCE_NAME)
+ .withVersion(TEMPLATE_VERSION_ONE)
+ .withDescription(BUILD_DESCRIPTION)
+ .withUrl(BUILD_URL);
+ int expectedHash = 221277984;
+ assertEquals(expectedHash, builder.hashCode());
+ }
+
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/TemplateVersionKeyDeserializerTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/TemplateVersionKeyDeserializerTest.java
new file mode 100644
index 0000000..39eb5ca
--- /dev/null
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/TemplateVersionKeyDeserializerTest.java
@@ -0,0 +1,22 @@
+package com.blazemeter.jmeter.correlation.core.templates;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TemplateVersionKeyDeserializerTest {
+
+ private static final String SIEBEL_TEMPLATE_REFERENCE_NAME = "siebel";
+ private static final String TEMPLATE_VERSION_ONE = "1.0";
+ private static final String TEMPLATE_FILE_SUFFIX = "template.json";
+ private static final String SIEBEL_TEMPLATE_VERSION_ONE_NAME = SIEBEL_TEMPLATE_REFERENCE_NAME + "-" + TEMPLATE_VERSION_ONE + "-" + TEMPLATE_FILE_SUFFIX;
+
+ @Test
+ public void shouldReturnTemplateVersionWhenDeserializeKey() {
+ TemplateVersionKeyDeserializer templateVersionDeserializer = new TemplateVersionKeyDeserializer();
+ TemplateVersion tversion = (TemplateVersion) templateVersionDeserializer.deserializeKey(SIEBEL_TEMPLATE_VERSION_ONE_NAME, null);
+ assertEquals(SIEBEL_TEMPLATE_REFERENCE_NAME + " " + TEMPLATE_VERSION_ONE, tversion.toString());
+ assertEquals(SIEBEL_TEMPLATE_REFERENCE_NAME, tversion.getName());
+ assertEquals(TEMPLATE_VERSION_ONE, tversion.getVersion());
+ }
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/core/templates/WiredBaseTest.java b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/WiredBaseTest.java
new file mode 100644
index 0000000..1126162
--- /dev/null
+++ b/src/test/java/com/blazemeter/jmeter/correlation/core/templates/WiredBaseTest.java
@@ -0,0 +1,90 @@
+package com.blazemeter.jmeter.correlation.core.templates;
+
+import com.blazemeter.jmeter.correlation.TestUtils;
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.client.MappingBuilder;
+
+import java.io.IOException;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.head;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+
+public class WiredBaseTest {
+ protected final WireMockServer wireMockServer = new WireMockServer(wireMockConfig().dynamicPort());
+
+ protected static final String WIRED_HOST = "localhost";
+ protected static final String TEST_REPOSITORY_URL = "/test-repository.json";
+ protected static final String FIRST_1_0_TEMPLATE_URL = "/first-1.0-template.json";
+ protected static final String FIRST_1_0_SNAPSHOT_URL = "/first-1.0-snapshot.png";
+ protected static final String FIRST_1_1_TEMPLATE_URL = "/first-1.1-template.json";
+ protected static final String FIRST_1_1_SNAPSHOT_URL = "/first-1.1-snapshot.png";
+ protected static final String SECOND_1_0_TEMPLATE_URL = "/second-1.0-template.json";
+ protected static final String SECOND_1_0_SNAPSHOT_URL = "/second-1.0-snapshot.png";
+
+ protected void startWiredMock(){
+ startWiredMock("");
+ }
+ protected void startWiredMock(String scenario){
+ wireMockServer.start();
+ configureFor(WIRED_HOST, wireMockServer.port());
+ if (scenario != null && !scenario.isEmpty()){
+ wireMockServer.startRecording(scenario);
+ }
+ }
+
+ protected void stopWiredMock(){
+ if (wireMockServer.isRunning()) {
+ wireMockServer.stop();
+ }
+ }
+
+ protected MappingBuilder prepareURL(String URL) throws IOException {
+ return mockingResponse(URL, 200, TestUtils.getFileContent(URL, getClass()), "get");
+ }
+
+ public MappingBuilder mockingResponse(String URL, int status, String body, String method) {
+ MappingBuilder routeMapping;
+ if (method.equals("head")) {
+ routeMapping = head(urlEqualTo(URL));
+ } else {
+ routeMapping = get(urlEqualTo(URL));
+ }
+
+ wireMockServer.stubFor(routeMapping.willReturn(aResponse()
+ .withStatus(status)
+ .withBody(body)
+ .withHeader("Cache-Control", "no-cache")
+ .withHeader("Content-Type", "application/json")));
+ return routeMapping;
+ }
+
+ protected void skipURL(String URL) {
+ stubFor(get(urlEqualTo(URL)).willReturn(aResponse()
+ .withStatus(304)
+ ));
+ }
+
+ protected void mockRequestsToRepoFiles() throws IOException {
+ prepareURL(TEST_REPOSITORY_URL);
+ prepareURL(FIRST_1_0_TEMPLATE_URL);
+ skipURL(FIRST_1_0_SNAPSHOT_URL);
+ prepareURL(FIRST_1_1_TEMPLATE_URL);
+ skipURL(FIRST_1_1_SNAPSHOT_URL);
+ prepareURL(SECOND_1_0_TEMPLATE_URL);
+ skipURL(SECOND_1_0_SNAPSHOT_URL);
+ }
+
+ protected String getBaseURL() {
+ return "http://" + WIRED_HOST + ":" + wireMockServer.port();
+ }
+
+
+ protected Integer getWiredPort(){
+ return wireMockServer.port();
+ }
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/gui/automatic/CorrelationHistoryFrameIT.java b/src/test/java/com/blazemeter/jmeter/correlation/gui/automatic/CorrelationHistoryFrameIT.java
new file mode 100644
index 0000000..7973e5d
--- /dev/null
+++ b/src/test/java/com/blazemeter/jmeter/correlation/gui/automatic/CorrelationHistoryFrameIT.java
@@ -0,0 +1,100 @@
+package com.blazemeter.jmeter.correlation.gui.automatic;
+
+import com.blazemeter.jmeter.correlation.SwingTestRunner;
+import com.blazemeter.jmeter.correlation.TestUtils;
+import com.blazemeter.jmeter.correlation.core.automatic.CorrelationHistory;
+import com.blazemeter.jmeter.correlation.core.automatic.CorrelationHistoryBaseTest;
+import com.blazemeter.jmeter.correlation.gui.automatic.CorrelationHistoryFrame;
+import org.apache.jmeter.util.JMeterUtils;
+import org.assertj.swing.edt.GuiActionRunner;
+import org.assertj.swing.fixture.FrameFixture;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.regex.Pattern;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static org.assertj.swing.data.TableCell.row;
+import static org.assertj.swing.fixture.Containers.showInFrame;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(SwingTestRunner.class)
+public class CorrelationHistoryFrameIT extends CorrelationHistoryBaseTest {
+
+ private CorrelationHistoryFrame historyFrame;
+ private FrameFixture frame;
+ private CorrelationHistory history;
+
+
+ @Before
+ public void setUp() throws IOException {
+
+ setupHistoryFiles();
+
+ history = CorrelationHistory.loadFromFile(HISTORY_FILE_ID);
+
+ historyFrame = new CorrelationHistoryFrame(history);
+ historyFrame.loadSteps(history.getSteps());
+ frame = showInFrame(historyFrame.getContentPane());
+ }
+
+ @After
+ public void tearDown() {
+ frame.cleanUp();
+ frame = null;
+ }
+
+ @Test
+ public void shouldHaveNoRowSelectedWhenCreated() {
+ assertEquals(0,frame.table("historyTable").target().getSelectedRowCount());
+ }
+
+ @Test
+ public void shouldDisplayMessageWhenRestoreButtonClickedWithMoreThanOneRowSelected() {
+ frame.table("historyTable").cell(row(0).column(0)).click();
+ frame.table("historyTable").cell(row(1).column(0)).click();
+ frame.button("restoreStepButton").click();
+ frame.optionPane().requireMessage("You can't restore more than one iteration at a time.");
+ }
+
+ @Test
+ public void shouldDisplayMessageWhenRestoreButtonClickedWithNoRowSelected() {
+ frame.button("restoreStepButton").click();
+ frame.optionPane().requireMessage("Please select one iteration to restore");
+ }
+
+ @Test
+ public void shouldEnableDeleteButtonWithMoreThanOneRowSelected() {
+ frame.table("historyTable").cell(row(0).column(0)).click();
+ frame.table("historyTable").cell(row(1).column(0)).click();
+ assertTrue(frame.button("deleteStepsButton").isEnabled());
+ }
+
+ @Test
+ public void shouldShowWarningWhenDeleteButtonIsClicked() {
+ frame.table("historyTable").cell(row(0).column(0)).click();
+ frame.table("historyTable").cell(row(1).column(0)).click();
+ frame.button("deleteStepsButton").click();
+ frame.optionPane().requireMessage("You are about to delete one or more history iterations.\n" +
+ "Do you want to continue? \n");
+
+ }
+
+ @Test
+ public void shouldShowSuccessMessageWhenZipButtonIsClicked() {
+ frame.button("zipSaveButton").click();
+ frame.optionPane().requireMessage(Pattern.compile("History zipped at: \n.*"));
+ }
+
+}
diff --git a/src/test/java/com/blazemeter/jmeter/correlation/gui/templates/TemplateSaveFrameIT.java b/src/test/java/com/blazemeter/jmeter/correlation/gui/templates/TemplateSaveFrameIT.java
index 2863515..fd253ab 100644
--- a/src/test/java/com/blazemeter/jmeter/correlation/gui/templates/TemplateSaveFrameIT.java
+++ b/src/test/java/com/blazemeter/jmeter/correlation/gui/templates/TemplateSaveFrameIT.java
@@ -35,7 +35,6 @@
@RunWith(SwingTestRunner.class)
public class TemplateSaveFrameIT extends BaseTest {
- private final List lastLoadedTemplates = new ArrayList();
private FrameFixture frame;
@Mock
private Template registeredTemplate;
@@ -44,6 +43,7 @@ public class TemplateSaveFrameIT extends BaseTest {
@Mock
private BufferedImage snapshot;
private TemplateSaveFrame templateSaveFrame;
+ private final List lastLoadedTemplates = new ArrayList();
@Before
public void setup() {
@@ -110,7 +110,6 @@ private JTabbedPaneFixture selectTabByIndex(int index) {
private JComboBoxFixture findRepositoriesComboBox() {
return frame.comboBox("repositoriesComboBox");
}
-
private JComboBoxFixture findProtocolsComboBox() {
return frame.comboBox("protocolsComboBox");
}
@@ -253,7 +252,7 @@ private void prepareRegisteredTemplate() {
when(registeredTemplate.getVersion()).thenReturn(TEMPLATE_VERSION);
when(registeredTemplate.getDescription()).thenReturn(TEMPLATE_DESCRIPTION);
when(registeredTemplate.getDependencies())
- .thenReturn(Arrays.asList(firstDependency, secondDependency));
+ .thenReturn(Arrays.asList(firstDependency, secondDependency));
}
private void prepareDependencyAndUrlValidity(CorrelationTemplateDependency dependency,
@@ -279,6 +278,7 @@ private String buildEmptyFieldMessage() {
return "Field cannot be empty.";
}
+
private JLabelFixture findTemplateNameValidationLabel() {
return frame.label("protocolValidation");
}
@@ -340,6 +340,6 @@ public void shouldLoadMultipleDependenciesWhenLoadWithMultipleLoadedTemplates()
lastLoadedTemplates.add(lastLoadedTemplate);
templateSaveFrame.updateLastLoadedTemplate(getLastLoadedTemplate());
assertThat(templateSaveFrame.getDependenciesTable().getDependencies().size())
- .isEqualTo(lastLoadedTemplate.getDependencies().size());
+ .isEqualTo(lastLoadedTemplate.getDependencies().size());
}
}
diff --git a/src/test/resources/history-test.json b/src/test/resources/history-test.json
new file mode 100644
index 0000000..f6efb9f
--- /dev/null
+++ b/src/test/resources/history-test.json
@@ -0,0 +1,22 @@
+{
+ "steps" : [ {
+ "stepMessage" : "Original Recording",
+ "testPlanFilepath" : "Recording/snapshot-1.jmx",
+ "recordingTraceFilepath" : "Recording/recording-1.jtl",
+ "replayTraceFilepath" : null,
+ "timestamp" : "2024-01-22T11:26:20.230"
+ }, {
+ "stepMessage" : "Failed Replay",
+ "testPlanFilepath" : "Recording/snapshot-2.jmx",
+ "recordingTraceFilepath" : null,
+ "replayTraceFilepath" : "Replay/replay-2.jtl",
+ "timestamp" : "2024-01-22T11:28:20.230"
+ }, {
+ "stepMessage" : "(Save) Before apply suggestions",
+ "testPlanFilepath" : "Recording/snapshot-3.jmx",
+ "recordingTraceFilepath" : null,
+ "replayTraceFilepath" : null,
+ "timestamp" : "2024-01-22T11:29:20.230"
+ } ],
+ "historyId" : "test"
+}
\ No newline at end of file