@Test public void testChanges_reduntantLinksAndTags() { ChangesContext changes = new ChangesContext(); JunitResource r1 = new JunitResource("reduntant_1"); JunitResource r2 = new JunitResource("reduntant_2"); changes.getResourcesToAdd().add(r1); changes.getResourcesToAdd().add(r2); changes.getLinksToAdd().add(new Tuple3<>(r1, "link1", r2)); changes.getLinksToAdd().add(new Tuple3<>(r1, "link1", r2)); changes.getLinksToAdd().add(new Tuple3<>(r1, "link2", r2)); changes.getTagsToAdd().add(new Tuple2<>(r1, "tag1")); changes.getTagsToAdd().add(new Tuple2<>(r1, "tag1")); changes.getTagsToAdd().add(new Tuple2<>(r1, "tag2")); getInternalServicesContext().getInternalChangeService().changesExecute(changes); // Check IPResourceService resourceService = getCommonServicesContext().getResourceService(); r1 = resourceService.resourceFindByPk(r1).get(); r2 = resourceService.resourceFindByPk(r2).get(); Assert.assertEquals(Arrays.asList("link1", "link2"), resourceService.linkFindAllByFromResource(r1).stream().map(it -> it.getA()).sorted().collect(Collectors.toList())); Assert.assertEquals(Arrays.asList("tag1", "tag2"), resourceService.tagFindAllByResource(r1).stream().sorted().collect(Collectors.toList())); }
public static void createFakeData(InternalServicesContext ctx) { // JunitResource ChangesContext changes = new ChangesContext(); JunitResource junitResource = new JunitResource("www.example.com", JunitResourceEnum.A, 1); changes.getResourcesToAdd().add(junitResource); changes.getTagsToAdd().addAll(Arrays.asList( // new Tuple2<>(junitResource, "tag1"), // new Tuple2<>(junitResource, "asite"))); junitResource = new JunitResource("www.example.com", JunitResourceEnum.A, 2); changes.getResourcesToAdd().add(junitResource); changes.getTagsToAdd().addAll(Arrays.asList( // new Tuple2<>(junitResource, "asite"))); changes.getResourcesToAdd().add(new JunitResource("example.com", JunitResourceEnum.B, 3)); changes.getResourcesToAdd().add(new JunitResource("t1_aaa", JunitResourceEnum.A, DateTools.parseFull("2000-01-01 00:00:00"), 1, 1L, 1.0, 1.0f, true, "one", "two")); changes.getResourcesToAdd().add(new JunitResource("t2_aaa", JunitResourceEnum.C, DateTools.parseFull("2000-06-01 00:00:00"), 5, 8L, 1.5, 7.3f, false, "one", "three")); changes.getResourcesToAdd().add(new JunitResource("zz", JunitResourceEnum.B, DateTools.parseFull("2000-04-01 00:00:00"), 80, 4L, 77.6, 3.1f, true)); ctx.getInternalChangeService().changesExecute(changes); }
@Test public void testChanges_reduntantLinksAndTags() { ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); JunitResource r1 = new JunitResource("reduntant_1"); JunitResource r2 = new JunitResource("reduntant_2"); changes.resourceAdd(r1); changes.resourceAdd(r2); changes.linkAdd(r1, "link1", r2); changes.linkAdd(r1, "link1", r2); changes.linkAdd(r1, "link2", r2); changes.tagAdd(r1, "tag1"); changes.tagAdd(r1, "tag1"); changes.tagAdd(r1, "tag2"); getInternalServicesContext().getInternalChangeService().changesExecute(changes); // Check IPResourceService resourceService = getCommonServicesContext().getResourceService(); r1 = resourceService.resourceFindByPk(r1).get(); r2 = resourceService.resourceFindByPk(r2).get(); Assert.assertEquals(Arrays.asList("link1", "link2"), resourceService.linkFindAllByFromResource(r1).stream().map(it -> it.getA()).sorted().collect(Collectors.toList())); Assert.assertEquals(Arrays.asList("tag1", "tag2"), resourceService.tagFindAllByResource(r1).stream().sorted().collect(Collectors.toList())); }
private void deleteAllResources() { ChangesContext changes = new ChangesContext(); for (IPResource resource : getInternalServicesContext().getInternalIPResourceService().resourceFindAll()) { changes.getResourcesToDelete().add(resource.getInternalId()); } getInternalServicesContext().getInternalChangeService().changesExecute(changes); }
@Test public void testChanges_linksAndTagsAreNotKeptWhenDeleted() { // Create ChangesContext changes = new ChangesContext(); JunitResource r1 = new JunitResource("1"); JunitResource r2 = new JunitResource("2"); changes.getResourcesToAdd().add(r1); changes.getResourcesToAdd().add(r2); changes.getLinksToAdd().add(new Tuple3<>(r1, "link1", r2)); changes.getTagsToAdd().add(new Tuple2<>(r1, "tag1")); getInternalServicesContext().getInternalChangeService().changesExecute(changes); IPResourceService resourceService = getCommonServicesContext().getResourceService(); r1 = resourceService.resourceFindByPk(r1).get(); r2 = resourceService.resourceFindByPk(r2).get(); Assert.assertEquals(Arrays.asList("link1"), resourceService.linkFindAllByFromResource(r1).stream().map(it -> it.getA()).sorted().collect(Collectors.toList())); Assert.assertEquals(Arrays.asList("tag1"), resourceService.tagFindAllByResource(r1).stream().sorted().collect(Collectors.toList())); // Delete it changes.getResourcesToDelete().add(resourceService.resourceFindByPk(r1).get().getInternalId()); getInternalServicesContext().getInternalChangeService().changesExecute(changes); Assert.assertEquals(0, resourceService.linkFindAllByFromResource(r1).size()); Assert.assertEquals(0, resourceService.tagFindAllByResource(r1).size()); // Recreate it changes.getResourcesToAdd().add(r1); getInternalServicesContext().getInternalChangeService().changesExecute(changes); // Check no links and tags Assert.assertEquals(0, resourceService.linkFindAllByFromResource(r1).size()); Assert.assertEquals(0, resourceService.tagFindAllByResource(r1).size()); }
@Test public void testChanges_linksAndTagsAreNotKeptWhenDeleted() { // Create ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); JunitResource r1 = new JunitResource("1"); JunitResource r2 = new JunitResource("2"); changes.resourceAdd(r1); changes.resourceAdd(r2); changes.linkAdd(r1, "link1", r2); changes.tagAdd(r1, "tag1"); getInternalServicesContext().getInternalChangeService().changesExecute(changes); IPResourceService resourceService = getCommonServicesContext().getResourceService(); r1 = resourceService.resourceFindByPk(r1).get(); r2 = resourceService.resourceFindByPk(r2).get(); Assert.assertEquals(Arrays.asList("link1"), resourceService.linkFindAllByFromResource(r1).stream().map(it -> it.getA()).sorted().collect(Collectors.toList())); Assert.assertEquals(Arrays.asList("tag1"), resourceService.tagFindAllByResource(r1).stream().sorted().collect(Collectors.toList())); // Delete it changes.resourceDelete(resourceService.resourceFindByPk(r1).get().getInternalId()); getInternalServicesContext().getInternalChangeService().changesExecute(changes); Assert.assertEquals(0, resourceService.linkFindAllByFromResource(r1).size()); Assert.assertEquals(0, resourceService.tagFindAllByResource(r1).size()); // Recreate it changes.resourceAdd(r1); getInternalServicesContext().getInternalChangeService().changesExecute(changes); // Check no links and tags Assert.assertEquals(0, resourceService.linkFindAllByFromResource(r1).size()); Assert.assertEquals(0, resourceService.tagFindAllByResource(r1).size()); }
@Test public void testDuplicatePkSameResource_create() { // Common JunitResource resource; ChangesContext changes = new ChangesContext(); InternalChangeService internalChangeService = getInternalServicesContext().getInternalChangeService(); // Create 1 item resource = new JunitResource("t1", JunitResourceEnum.A, 1); resource.setLongNumber(10L); changes.getResourcesToAdd().add(resource); internalChangeService.changesExecute(changes); // Create same. Not fine thrown.expect(ResourcePrimaryKeyCollisionException.class); resource = new JunitResource("t1", JunitResourceEnum.A, 1); resource.setLongNumber(30L); changes.getResourcesToAdd().add(resource); internalChangeService.changesExecute(changes); }
private void deleteAllResources() { ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); for (IPResource resource : getInternalServicesContext().getInternalIPResourceService().resourceFindAll()) { changes.resourceDelete(resource); } getInternalServicesContext().getInternalChangeService().changesExecute(changes); }
@Test public void testQueryEditorName() { IPResourceService resourceService = getCommonServicesContext().getResourceService(); InternalChangeService internalChangeService = getInternalServicesContext().getInternalChangeService(); // Get the initial id Optional<JunitResource> junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .propertyEquals(JunitResource.PROPERTY_SET_TEXTS, "two")// ); Assert.assertTrue(junitResourceOptional.isPresent()); long expectedId = junitResourceOptional.get().getInternalId(); // Modify its editor JunitResource resource = junitResourceOptional.get(); ChangesContext changes = new ChangesContext(); resource.setResourceEditorName("junit"); changes.getResourcesToUpdate().add(new Tuple2<>(expectedId, resource)); internalChangeService.changesExecute(changes); // Get the resource junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .addEditorEquals("junit") // ); Assert.assertTrue(junitResourceOptional.isPresent()); Assert.assertEquals((Long) expectedId, junitResourceOptional.get().getInternalId()); // Don't get the resource if wrong editor junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .addEditorEquals("not junit") // ); Assert.assertFalse(junitResourceOptional.isPresent()); }
@Test public void testQueryEditorName() { IPResourceService resourceService = getCommonServicesContext().getResourceService(); InternalChangeService internalChangeService = getInternalServicesContext().getInternalChangeService(); // Get the initial id Optional<JunitResource> junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .propertyContains(JunitResource.PROPERTY_SET_TEXTS, Arrays.asList("two"))// ); Assert.assertTrue(junitResourceOptional.isPresent()); long expectedId = junitResourceOptional.get().getInternalId(); // Modify its editor JunitResource resource = junitResourceOptional.get(); ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); resource.setResourceEditorName("junit"); changes.resourceUpdate(expectedId, resource); internalChangeService.changesExecute(changes); // Get the resource junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .addEditorEquals("junit") // ); Assert.assertTrue(junitResourceOptional.isPresent()); Assert.assertEquals((Long) expectedId, junitResourceOptional.get().getInternalId()); // Don't get the resource if wrong editor junitResourceOptional = resourceService.resourceFind(resourceService.createResourceQuery(JunitResource.class) // .addEditorEquals("not junit") // ); Assert.assertFalse(junitResourceOptional.isPresent()); }
@Test public void testDuplicatePkSameResource_update() { // Common JunitResource resource; ChangesContext changes = new ChangesContext(); InternalChangeService internalChangeService = getInternalServicesContext().getInternalChangeService(); IPResourceService resourceService = getCommonServicesContext().getResourceService(); // Create 2 items resource = new JunitResource("t1", JunitResourceEnum.A, 1); resource.setLongNumber(10L); changes.getResourcesToAdd().add(resource); resource = new JunitResource("t2", JunitResourceEnum.A, 2); resource.setLongNumber(10L); changes.getResourcesToAdd().add(resource); internalChangeService.changesExecute(changes); // Rename second item to same pk as first thrown.expect(ResourcePrimaryKeyCollisionException.class); resource = new JunitResource("t1", JunitResourceEnum.A, 1); resource.setLongNumber(20L); changes.getResourcesToUpdate().add(new Tuple2<>(resourceService.resourceFindByPk(new JunitResource("t2", JunitResourceEnum.A, 2)).get().getInternalId(), resource)); internalChangeService.changesExecute(changes); }
@Test(timeout = 30000) public void testInfiniteLoop() { thrown.expect(InfiniteUpdateLoop.class); TestingControllerPluginDefinitionProvider.getInstance().getTestingControllerInfiniteLoopUpdateHander().setAlwaysUpdate(true); ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); JunitResource resource = new JunitResource("OneToGetStarted"); changes.resourceAdd(resource); getInternalServicesContext().getInternalChangeService().changesExecute(changes); }
@Test public void testChanges_refresh() { // Create resource JunitResource junitResource = new JunitResource("testChanges_refresh"); ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); changes.resourceAdd(junitResource); getInternalServicesContext().getInternalChangeService().changesExecute(changes); // Reset TestingControllerMockUpdateHander testingControllerMockUpdateHander = TestingControllerPluginDefinitionProvider.getInstance().getTestingControllerMockUpdateHander(); testingControllerMockUpdateHander.clear(); Assert.assertEquals(0, testingControllerMockUpdateHander.getChecked().size()); // Refresh resource changes.resourceRefresh(junitResource); getInternalServicesContext().getInternalChangeService().changesExecute(changes); // Assert Assert.assertEquals(1, testingControllerMockUpdateHander.getChecked().size()); }
@Test public void testResourceUrlRedirection() { deleteAllResources(); IPResourceService resourceService = getCommonServicesContext().getResourceService(); // Create initial data Machine m1 = new Machine("m1.example.com", "199.141.1.101"); Machine m2 = new Machine("m2.example.com", "199.141.1.201"); ChangesContext changes = new ChangesContext(); changes.getResourcesToAdd().add(m1); changes.getResourcesToAdd().add(m2); getInternalServicesContext().getInternalChangeService().changesExecute(changes); assertState("UrlRedirectionTest-state-0.json"); // Create a redirection UrlRedirection urlRedirection = new UrlRedirection(); urlRedirection.setDomainName("redir.example.com"); urlRedirection.setHttpRedirectToUrl("https://google.com"); changes.getResourcesToAdd().add(urlRedirection); changes.getLinksToAdd().add(new Tuple3<>(urlRedirection, LinkTypeConstants.INSTALLED_ON, m1)); getInternalServicesContext().getInternalChangeService().changesExecute(changes); urlRedirection = resourceService.resourceFindByPk(urlRedirection).get(); assertState("UrlRedirectionTest-state-1.json"); // Change the list of machines changes.getLinksToAdd().add(new Tuple3<>(urlRedirection, LinkTypeConstants.INSTALLED_ON, m2)); getInternalServicesContext().getInternalChangeService().changesExecute(changes); assertState("UrlRedirectionTest-state-2.json"); // Delete changes.getResourcesToDelete().add(urlRedirection.getInternalId()); getInternalServicesContext().getInternalChangeService().changesExecute(changes); assertState("UrlRedirectionTest-state-3.json"); }
@Test public void testDuplicatePkSameResource_create() { // Common JunitResource resource; ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); InternalChangeService internalChangeService = getInternalServicesContext().getInternalChangeService(); // Create 1 item resource = new JunitResource("t1", JunitResourceEnum.A, 1); resource.setLongNumber(10L); changes.resourceAdd(resource); internalChangeService.changesExecute(changes); // Create same. Not fine thrown.expect(ResourcePrimaryKeyCollisionException.class); resource = new JunitResource("t1", JunitResourceEnum.A, 1); resource.setLongNumber(30L); changes.resourceAdd(resource); internalChangeService.changesExecute(changes); }
@Test public void testDuplicatePkSameResource_update() { // Common JunitResource resource; ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); InternalChangeService internalChangeService = getInternalServicesContext().getInternalChangeService(); IPResourceService resourceService = getCommonServicesContext().getResourceService(); // Create 2 items resource = new JunitResource("t1", JunitResourceEnum.A, 1); resource.setLongNumber(10L); changes.resourceAdd(resource); resource = new JunitResource("t2", JunitResourceEnum.A, 2); resource.setLongNumber(10L); changes.resourceAdd(resource); internalChangeService.changesExecute(changes); // Rename second item to same pk as first thrown.expect(ResourcePrimaryKeyCollisionException.class); resource = new JunitResource("t1", JunitResourceEnum.A, 1); resource.setLongNumber(20L); changes.resourceUpdate(resourceService.resourceFindByPk(new JunitResource("t2", JunitResourceEnum.A, 2)).get().getInternalId(), resource); internalChangeService.changesExecute(changes); }
ChangesContext changes = new ChangesContext(); changes.getResourcesToAdd().add(c1); getInternalServicesContext().getInternalChangeService().changesExecute(changes);
public static void createFakeData(CommonServicesContext commonCtx, InternalServicesContext internalCtx) { // JunitResource ChangesContext changes = new ChangesContext(commonCtx.getResourceService()); JunitResource junitResource = new JunitResource("www.example.com", JunitResourceEnum.A, 1); changes.resourceAdd(junitResource); changes.tagAdd(junitResource, "tag1"); changes.tagAdd(junitResource, "asite"); junitResource = new JunitResource("www.example.com", JunitResourceEnum.A, 2); changes.resourceAdd(junitResource); changes.tagAdd(junitResource, "asite"); changes.resourceAdd(new JunitResource("example.com", JunitResourceEnum.B, 3)); changes.resourceAdd(new JunitResource("t1_aaa", JunitResourceEnum.A, DateTools.parseFull("2000-01-01 00:00:00"), 1, 1L, 1.0, 1.0f, true, "one", "two")); changes.resourceAdd(new JunitResource("t2_aaa", JunitResourceEnum.C, DateTools.parseFull("2000-06-01 00:00:00"), 5, 8L, 1.5, 7.3f, false, "one", "three")); changes.resourceAdd(new JunitResource("zz", JunitResourceEnum.B, DateTools.parseFull("2000-04-01 00:00:00"), 80, 4L, 77.6, 3.1f, true)); internalCtx.getInternalChangeService().changesExecute(changes); }
ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); changes.resourceAdd(c1); getInternalServicesContext().getInternalChangeService().changesExecute(changes);
ChangesContext changes = new ChangesContext(getCommonServicesContext().getResourceService()); Machine machine = new Machine("m1.node.example.com", "199.141.1.101"); changes.resourceAdd(machine);