@Test public void testUpdateMetaData() { final String updatedMetaData = "{\"updated\":\"meta-data\"}"; final String resourceName = "update-my-meta-data.txt"; Group mockGroup = mock(Group.class); WebServer mockWebServer = mock(WebServer.class); Set<WebServer> groupSet = new HashSet<>(); groupSet.add(mockWebServer); when(mockGroup.getWebServers()).thenReturn(groupSet); when(mockWebServer.getName()).thenReturn("webserver-name"); when(mockGroupPersistence.getGroupWithWebServers(anyString())).thenReturn(mockGroup); when(mockGroupPersistence.updateGroupWebServerResourceMetaData(anyString(), anyString(), anyString())).thenReturn(updatedMetaData); groupLevelWebServerResourceHandler.updateResourceMetaData(resourceIdentifier, resourceName, updatedMetaData); verify(mockGroupPersistence).updateGroupWebServerResourceMetaData(eq(resourceIdentifier.groupName), eq(resourceName), eq(updatedMetaData)); verify(mockWebServerPersistence).updateResourceMetaData(eq(mockWebServer.getName()), eq(resourceName), eq(updatedMetaData)); }
@Override public String updateResourceMetaData(ResourceIdentifier resourceIdentifier, String resourceName, String metaData) { if (canHandle(resourceIdentifier)) { final String updatedMetaData = groupPersistenceService.updateGroupWebServerResourceMetaData(resourceIdentifier.groupName, resourceName, metaData); Set<WebServer> webServersSet = groupPersistenceService.getGroupWithWebServers(resourceIdentifier.groupName).getWebServers(); for (WebServer webServer : webServersSet){ webServerPersistenceService.updateResourceMetaData(webServer.getName(), resourceName, metaData); } return updatedMetaData; } else { return successor.updateResourceMetaData(resourceIdentifier, resourceName, metaData); } }
GroupLevelWebServerResourceHandler extends ResourceHandler { @Override public String updateResourceMetaData(ResourceIdentifier resourceIdentifier, String resourceName, String metaData) { if (canHandle(resourceIdentifier)) { final String updatedMetaData = groupPersistenceService.updateGroupWebServerResourceMetaData(resourceIdentifier.groupName, resourceName, metaData); Set<WebServer> webServersSet = groupPersistenceService.getGroupWithWebServers(resourceIdentifier.groupName).getWebServers(); for (WebServer webServer : webServersSet){ webServerPersistenceService.updateResourceMetaData(webServer.getName(), resourceName, metaData); } return updatedMetaData; } else { return successor.updateResourceMetaData(resourceIdentifier, resourceName, metaData); } } }
GroupLevelWebServerResourceHandler extends ResourceHandler { @Override public String updateResourceMetaData(ResourceIdentifier resourceIdentifier, String resourceName, String metaData) { if (canHandle(resourceIdentifier)) { final String updatedMetaData = groupPersistenceService.updateGroupWebServerResourceMetaData(resourceIdentifier.groupName, resourceName, metaData); Set<WebServer> webServersSet = groupPersistenceService.getGroupWithWebServers(resourceIdentifier.groupName).getWebServers(); for (WebServer webServer : webServersSet){ webServerPersistenceService.updateResourceMetaData(webServer.getName(), resourceName, metaData); } return updatedMetaData; } else { return successor.updateResourceMetaData(resourceIdentifier, resourceName, metaData); } } GroupLevelWebServerResourceHandler(final ResourceDao resourceDao,
                                              final GroupPersistenceService groupPersistenceService,
                                              final WebServerPersistenceService webServerPersistenceService,
                                              final ResourceContentGeneratorService resourceContentGeneratorService,
                                              final ResourceHandler successor); }
GroupLevelWebServerResourceHandler extends ResourceHandler { @Override public String updateResourceMetaData(ResourceIdentifier resourceIdentifier, String resourceName, String metaData) { if (canHandle(resourceIdentifier)) { final String updatedMetaData = groupPersistenceService.updateGroupWebServerResourceMetaData(resourceIdentifier.groupName, resourceName, metaData); Set<WebServer> webServersSet = groupPersistenceService.getGroupWithWebServers(resourceIdentifier.groupName).getWebServers(); for (WebServer webServer : webServersSet){ webServerPersistenceService.updateResourceMetaData(webServer.getName(), resourceName, metaData); } return updatedMetaData; } else { return successor.updateResourceMetaData(resourceIdentifier, resourceName, metaData); } } GroupLevelWebServerResourceHandler(final ResourceDao resourceDao,
                                              final GroupPersistenceService groupPersistenceService,
                                              final WebServerPersistenceService webServerPersistenceService,
                                              final ResourceContentGeneratorService resourceContentGeneratorService,
                                              final ResourceHandler successor); @Override ConfigTemplate fetchResource(final ResourceIdentifier resourceIdentifier); @Override CreateResourceResponseWrapper createResource(final ResourceIdentifier resourceIdentifier,
                                                        final ResourceTemplateMetaData metaData,
                                                        final String templateContent); @Override void deleteResource(final ResourceIdentifier resourceIdentifier); @Override String updateResourceMetaData(ResourceIdentifier resourceIdentifier, String resourceName, String metaData); @Override Object getSelectedValue(ResourceIdentifier resourceIdentifier); @Override List<String> getResourceNames(ResourceIdentifier resourceIdentifier); }
GroupLevelWebServerResourceHandler extends ResourceHandler { @Override public String updateResourceMetaData(ResourceIdentifier resourceIdentifier, String resourceName, String metaData) { if (canHandle(resourceIdentifier)) { final String updatedMetaData = groupPersistenceService.updateGroupWebServerResourceMetaData(resourceIdentifier.groupName, resourceName, metaData); Set<WebServer> webServersSet = groupPersistenceService.getGroupWithWebServers(resourceIdentifier.groupName).getWebServers(); for (WebServer webServer : webServersSet){ webServerPersistenceService.updateResourceMetaData(webServer.getName(), resourceName, metaData); } return updatedMetaData; } else { return successor.updateResourceMetaData(resourceIdentifier, resourceName, metaData); } } GroupLevelWebServerResourceHandler(final ResourceDao resourceDao,
                                              final GroupPersistenceService groupPersistenceService,
                                              final WebServerPersistenceService webServerPersistenceService,
                                              final ResourceContentGeneratorService resourceContentGeneratorService,
                                              final ResourceHandler successor); @Override ConfigTemplate fetchResource(final ResourceIdentifier resourceIdentifier); @Override CreateResourceResponseWrapper createResource(final ResourceIdentifier resourceIdentifier,
                                                        final ResourceTemplateMetaData metaData,
                                                        final String templateContent); @Override void deleteResource(final ResourceIdentifier resourceIdentifier); @Override String updateResourceMetaData(ResourceIdentifier resourceIdentifier, String resourceName, String metaData); @Override Object getSelectedValue(ResourceIdentifier resourceIdentifier); @Override List<String> getResourceNames(ResourceIdentifier resourceIdentifier);  }