### Question:
ROADMRepository extends ResourceRepository { public void capabilityFactoryAdded(ICapabilityFactory capabilityFactory) { log.info("Adding factory: " + capabilityFactory.getType()); this.capabilityFactories.put(capabilityFactory.getType(), capabilityFactory); } ROADMRepository(String resourceType); void capabilityFactoryAdded(ICapabilityFactory capabilityFactory); void capabilityFactoryDeleted(ICapabilityFactory capabilityFactory);  }### Answer:
@Test public void testCapabilityFactories() { roadmRepository = new ROADMRepository("ROADMrepository"); roadmRepository.setResourceDescriptorRepository(new MockDescriptorRepository()); roadmRepository.capabilityFactoryAdded(new MockCapabilityFactory("factory1")); roadmRepository.capabilityFactoryAdded(new MockCapabilityFactory("factory2")); Assert.assertTrue(roadmRepository.getCapabilityFactories().size() == 2); Assert.assertNotNull(roadmRepository.getCapabilityFactories().get("factory1")); Assert.assertNotNull(roadmRepository.getCapabilityFactories().get("factory2")); }
@Test public void testCreateRemoveResources() { roadmRepository = new ROADMRepository(resourceType); roadmRepository.setResourceDescriptorRepository(new MockDescriptorRepository()); roadmRepository.capabilityFactoryAdded(new MockCapabilityFactory("factory1")); roadmRepository.capabilityFactoryAdded(new MockCapabilityFactory("factory2")); try { ResourceDescriptor descriptor = newResourceDescriptor(resourceType, "router1"); IResource resource = roadmRepository.createResource(descriptor); String id = resource.getResourceIdentifier().getId(); Assert.assertNotNull(id); Assert.assertTrue(resource.getResourceDescriptor().equals(descriptor)); Assert.assertTrue(resource.getResourceIdentifier().getType().equals(resourceType)); boolean thrown = false; roadmRepository.removeResource(id); try { roadmRepository.getResource(id); } catch (Exception e) { thrown = true; } Assert.assertTrue(thrown); } catch (ResourceException e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
@Test public void testModifyResources() { roadmRepository = new ROADMRepository(resourceType); roadmRepository.setResourceDescriptorRepository(new MockDescriptorRepository()); roadmRepository.capabilityFactoryAdded(new MockCapabilityFactory("factory1")); roadmRepository.capabilityFactoryAdded(new MockCapabilityFactory("factory2")); try { IResource resource = roadmRepository.createResource(newResourceDescriptor(resourceType, "router1")); String id = resource.getResourceIdentifier().getId(); Assert.assertTrue(resource.getResourceDescriptor().getCapabilityDescriptors().size() == 2); Assert.assertTrue(resource.getResourceIdentifier().getType().equals(resourceType)); resource = roadmRepository.modifyResource(id, oldResourceDescriptor(id, resourceType, "router1")); IResource newResource = roadmRepository.getResource(resource.getResourceIdentifier().getId()); Assert.assertTrue(newResource.getResourceDescriptor().getCapabilityDescriptors().size() == 1); Assert.assertTrue(newResource.getResourceIdentifier().getType().equals(resourceType)); } catch (ResourceException e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }