ListProvidersScanner implements ArtifactInstaller { @Override public void install(File artifact) { String filePath = artifact.getAbsolutePath(); logger.info("Installing list provider {}", filePath); Properties properties; try { properties = readProperties(artifact); } catch (IOException e) { logger.error("Unable to read file " + filePath); return; } addResourceListProvider(filePath, properties); }  void setListProvidersService(ListProvidersService listProvidersService); @Override boolean canHandle(File artifact); @Override void install(File artifact); @Override void update(File artifact); @Override void uninstall(File artifact); static final String LIST_PROVIDERS_DIRECTORY; static final String LIST_NAME_KEY; static final String LIST_TRANSLATABLE_KEY; static final String LIST_ORG_KEY; static final String LIST_DEFAULT_KEY; }
@Test public void testDefaultInstall() throws Exception { EasyMock.expect(securityService.getOrganization()).andReturn(defaultOrg).anyTimes(); EasyMock.expect(defaultOrg.getId()).andReturn("mh_default_org").anyTimes(); File file = getResourceFile("/ListProvidersScannerTest-GoodProperties.properties"); listProvidersScanner.install(file); EasyMock.replay(securityService, defaultOrg); assertTrue("Provider has not been registered", listProvidersService.hasProvider(listName)); assertEquals(1, listProvidersService.getAvailableProviders().size()); assertEquals(3, listProvidersService .getList(listName, null, false).size() ); assertEquals(listName, listProvidersService.getAvailableProviders().get(0)); assertEquals("TEST.VALUE.1", listProvidersService .getList(listName, null, false) .get("TEST.KEY.1") ); }
@Test public void testSpecificOrgInstall() throws Exception { EasyMock.expect(securityService.getOrganization()).andReturn(specificOrg).anyTimes(); EasyMock.expect(specificOrg.getId()).andReturn("org1").anyTimes(); listName = "TEST.LIST.NAME"; File file = getResourceFile("/ListProvidersScannerTest-AllProperties.properties"); listProvidersScanner.install(file); EasyMock.replay(); assertTrue("Provider has not been registered", listProvidersService.hasProvider(listName, "org1")); }
@Test public void testIsTranslatable() throws Exception { EasyMock.expect(securityService.getOrganization()).andReturn(specificOrg).anyTimes(); EasyMock.expect(specificOrg.getId()).andReturn("org1").anyTimes(); listName = "TEST.LIST.NAME"; File file = getResourceFile("/ListProvidersScannerTest-AllProperties.properties"); listProvidersScanner.install(file); EasyMock.replay(securityService, specificOrg); assertTrue("Translatable property not read correctly", listProvidersService.isTranslatable(listName)); }
@Test public void testGetDefault() throws Exception { EasyMock.expect(securityService.getOrganization()).andReturn(specificOrg).anyTimes(); EasyMock.expect(specificOrg.getId()).andReturn("org1").anyTimes(); listName = "TEST.LIST.NAME"; File fileWithDefault = getResourceFile("/ListProvidersScannerTest-AllProperties.properties"); listProvidersScanner.install(fileWithDefault); EasyMock.replay(securityService, specificOrg); assertEquals("TEST.VALUE.1", listProvidersService.getDefault(listName)); }
@Test public void testThrowsExceptions() throws Exception { File file = getResourceFile("/ListProvidersScannerTest-WithOrg.properties"); listProvidersScanner.install(file); try { listProvidersService.getDefault(listName); } catch (ListProviderException e) { assertEquals("No provider found for organisation <*> with the name " + listName, e.getMessage()); } }
@Test public void testInstallInputMissingListNameInPropertiesFileExpectsNotAddedToService() throws Exception { File file = getResourceFile("/ListProvidersScannerTest-MissingListName.properties"); listProvidersScanner.install(file); assertFalse("Provider should not be added without a name", listProvidersService.hasProvider(listName)); }
@Test public void testInstallInputEmptyListNameInPropertiesFileExpectsNotAddedToService() throws Exception { File file = getResourceFile("/ListProvidersScannerTest-EmptyListName.properties"); listProvidersScanner.install(file); assertFalse("Provider should not be added without a name", listProvidersService.hasProvider(listName)); }
@Test public void testInstallInputOrgInPropertiesFileExpectsAddedToService() throws Exception { Organization org1 = EasyMock.createMock(Organization.class); EasyMock.expect(org1.getId()).andReturn("org1").anyTimes(); EasyMock.replay(org1); Organization org2 = EasyMock.createMock(Organization.class); EasyMock.expect(org2.getId()).andReturn("org2").anyTimes(); EasyMock.replay(org2); EasyMock.expect(securityService.getOrganization()).andReturn(org1).anyTimes(); EasyMock.replay(securityService); File file = getResourceFile("/ListProvidersScannerTest-WithOrg.properties"); listProvidersScanner.install(file); ResourceListQuery query = new ResourceListQueryImpl(); assertEquals(1, listProvidersService.getAvailableProviders().size()); assertEquals(listName, listProvidersService.getAvailableProviders().get(0)); assertEquals("org1", org1.getId()); assertTrue("Provider is not registered", listProvidersService.hasProvider(listName, org1.getId())); Map<String, String> dictionary = listProvidersService.getList(listName, query, false); assertEquals(3, dictionary.size()); assertEquals("TEST.VALUE.1", dictionary.get("TEST.KEY.1")); assertEquals("TEST.VALUE.2", dictionary.get("TEST.KEY.2")); assertEquals("TEST.VALUE.3", dictionary.get("TEST.KEY.3")); }