@Test public void testCreateResourceCallsSuccessor() throws IOException { ResourceIdentifier.Builder resourceIdentifierBuilder = new ResourceIdentifier.Builder(); resourceIdentifierBuilder.setGroupName("test-group-name"); resourceIdentifierBuilder.setWebAppName("test-app-name"); resourceIdentifierBuilder.setJvmName(null); resourceIdentifierBuilder.setWebServerName(null); resourceIdentifierBuilder.setResourceName("external.properties"); final ResourceTemplateMetaData metaData = resourceService.getMetaData("{\"deployFileName\": \"external.properties\"}"); CreateResourceResponseWrapper mockCreateResourceResponseWrapper = mock(CreateResourceResponseWrapper.class); when(mockSuccessor.createResource(any(ResourceIdentifier.class), any(ResourceTemplateMetaData.class), anyString())).thenReturn(mockCreateResourceResponseWrapper); CreateResourceResponseWrapper result = externalPropertiesResourceHandler.createResource(resourceIdentifierBuilder.build(), metaData, "key=value"); assertNotNull(result); verify(mockSuccessor).createResource(any(ResourceIdentifier.class), any(ResourceTemplateMetaData.class), anyString()); }
@Override public CreateResourceResponseWrapper createResource(final ResourceIdentifier resourceIdentifier, final ResourceTemplateMetaData metaData, final String templateContent) { CreateResourceResponseWrapper createResourceResponseWrapper = null; if (canHandle(resourceIdentifier)) { Long entityId = null; Long groupId = null; Long appId = null; EntityType entityType = EntityType.EXT_PROPERTIES; List<String> existingTemplateNames = resourceDao.getResourceNames(resourceIdentifier, EntityType.EXT_PROPERTIES); if (!existingTemplateNames.isEmpty()) { resourceDao.deleteExternalProperties(); ExternalProperties.reset(); } final String deployFileName = metaData.getDeployFileName(); createResourceResponseWrapper = new CreateResourceResponseWrapper(resourceDao.createResource(entityId, groupId, appId, entityType, deployFileName, templateContent, metaData.getJsonData())); String propertiesContent = resourceDao.getExternalPropertiesResource(deployFileName).getTemplateContent(); ExternalProperties.loadFromInputStream(new ByteArrayInputStream(propertiesContent.getBytes())); } else if (successor != null) { createResourceResponseWrapper = successor.createResource(resourceIdentifier, metaData, templateContent); } return createResourceResponseWrapper; }
ExternalPropertiesResourceHandler extends ResourceHandler { @Override public CreateResourceResponseWrapper createResource(final ResourceIdentifier resourceIdentifier, final ResourceTemplateMetaData metaData, final String templateContent) { CreateResourceResponseWrapper createResourceResponseWrapper = null; if (canHandle(resourceIdentifier)) { Long entityId = null; Long groupId = null; Long appId = null; EntityType entityType = EntityType.EXT_PROPERTIES; List<String> existingTemplateNames = resourceDao.getResourceNames(resourceIdentifier, EntityType.EXT_PROPERTIES); if (!existingTemplateNames.isEmpty()) { resourceDao.deleteExternalProperties(); ExternalProperties.reset(); } final String deployFileName = metaData.getDeployFileName(); createResourceResponseWrapper = new CreateResourceResponseWrapper(resourceDao.createResource(entityId, groupId, appId, entityType, deployFileName, templateContent, metaData.getJsonData())); String propertiesContent = resourceDao.getExternalPropertiesResource(deployFileName).getTemplateContent(); ExternalProperties.loadFromInputStream(new ByteArrayInputStream(propertiesContent.getBytes())); } else if (successor != null) { createResourceResponseWrapper = successor.createResource(resourceIdentifier, metaData, templateContent); } return createResourceResponseWrapper; } }
ExternalPropertiesResourceHandler extends ResourceHandler { @Override public CreateResourceResponseWrapper createResource(final ResourceIdentifier resourceIdentifier, final ResourceTemplateMetaData metaData, final String templateContent) { CreateResourceResponseWrapper createResourceResponseWrapper = null; if (canHandle(resourceIdentifier)) { Long entityId = null; Long groupId = null; Long appId = null; EntityType entityType = EntityType.EXT_PROPERTIES; List<String> existingTemplateNames = resourceDao.getResourceNames(resourceIdentifier, EntityType.EXT_PROPERTIES); if (!existingTemplateNames.isEmpty()) { resourceDao.deleteExternalProperties(); ExternalProperties.reset(); } final String deployFileName = metaData.getDeployFileName(); createResourceResponseWrapper = new CreateResourceResponseWrapper(resourceDao.createResource(entityId, groupId, appId, entityType, deployFileName, templateContent, metaData.getJsonData())); String propertiesContent = resourceDao.getExternalPropertiesResource(deployFileName).getTemplateContent(); ExternalProperties.loadFromInputStream(new ByteArrayInputStream(propertiesContent.getBytes())); } else if (successor != null) { createResourceResponseWrapper = successor.createResource(resourceIdentifier, metaData, templateContent); } return createResourceResponseWrapper; } ExternalPropertiesResourceHandler(final ResourceDao resourceDao, final ResourceHandler successor); }
ExternalPropertiesResourceHandler extends ResourceHandler { @Override public CreateResourceResponseWrapper createResource(final ResourceIdentifier resourceIdentifier, final ResourceTemplateMetaData metaData, final String templateContent) { CreateResourceResponseWrapper createResourceResponseWrapper = null; if (canHandle(resourceIdentifier)) { Long entityId = null; Long groupId = null; Long appId = null; EntityType entityType = EntityType.EXT_PROPERTIES; List<String> existingTemplateNames = resourceDao.getResourceNames(resourceIdentifier, EntityType.EXT_PROPERTIES); if (!existingTemplateNames.isEmpty()) { resourceDao.deleteExternalProperties(); ExternalProperties.reset(); } final String deployFileName = metaData.getDeployFileName(); createResourceResponseWrapper = new CreateResourceResponseWrapper(resourceDao.createResource(entityId, groupId, appId, entityType, deployFileName, templateContent, metaData.getJsonData())); String propertiesContent = resourceDao.getExternalPropertiesResource(deployFileName).getTemplateContent(); ExternalProperties.loadFromInputStream(new ByteArrayInputStream(propertiesContent.getBytes())); } else if (successor != null) { createResourceResponseWrapper = successor.createResource(resourceIdentifier, metaData, templateContent); } return createResourceResponseWrapper; } ExternalPropertiesResourceHandler(final ResourceDao resourceDao, final ResourceHandler successor); @Override ConfigTemplate fetchResource(ResourceIdentifier resourceIdentifier); @Override CreateResourceResponseWrapper createResource(final ResourceIdentifier resourceIdentifier,
                                                        final ResourceTemplateMetaData metaData,
                                                        final String templateContent); @Override void deleteResource(ResourceIdentifier resourceIdentifier); @Override String updateResourceMetaData(ResourceIdentifier resourceIdentifier, String resourceName, String metaData); @Override Object getSelectedValue(ResourceIdentifier resourceIdentifier); @Override List<String> getResourceNames(ResourceIdentifier resourceIdentifier); }
ExternalPropertiesResourceHandler extends ResourceHandler { @Override public CreateResourceResponseWrapper createResource(final ResourceIdentifier resourceIdentifier, final ResourceTemplateMetaData metaData, final String templateContent) { CreateResourceResponseWrapper createResourceResponseWrapper = null; if (canHandle(resourceIdentifier)) { Long entityId = null; Long groupId = null; Long appId = null; EntityType entityType = EntityType.EXT_PROPERTIES; List<String> existingTemplateNames = resourceDao.getResourceNames(resourceIdentifier, EntityType.EXT_PROPERTIES); if (!existingTemplateNames.isEmpty()) { resourceDao.deleteExternalProperties(); ExternalProperties.reset(); } final String deployFileName = metaData.getDeployFileName(); createResourceResponseWrapper = new CreateResourceResponseWrapper(resourceDao.createResource(entityId, groupId, appId, entityType, deployFileName, templateContent, metaData.getJsonData())); String propertiesContent = resourceDao.getExternalPropertiesResource(deployFileName).getTemplateContent(); ExternalProperties.loadFromInputStream(new ByteArrayInputStream(propertiesContent.getBytes())); } else if (successor != null) { createResourceResponseWrapper = successor.createResource(resourceIdentifier, metaData, templateContent); } return createResourceResponseWrapper; } ExternalPropertiesResourceHandler(final ResourceDao resourceDao, final ResourceHandler successor); @Override ConfigTemplate fetchResource(ResourceIdentifier resourceIdentifier); @Override CreateResourceResponseWrapper createResource(final ResourceIdentifier resourceIdentifier,
                                                        final ResourceTemplateMetaData metaData,
                                                        final String templateContent); @Override void deleteResource(ResourceIdentifier resourceIdentifier); @Override String updateResourceMetaData(ResourceIdentifier resourceIdentifier, String resourceName, String metaData); @Override Object getSelectedValue(ResourceIdentifier resourceIdentifier); @Override List<String> getResourceNames(ResourceIdentifier resourceIdentifier);  }