ConnectorDeployerService extends AbstractOpenEngSBService implements ArtifactInstaller { @Override public void install(File artifact) throws Exception { LOGGER.debug("ConnectorDeployer.install(\"{}\")", artifact.getAbsolutePath()); synchronized (failedInstalls) { if (!doInstall(artifact)) { failedInstalls.add(artifact); } } }  void init(); @Override boolean canHandle(File artifact); @Override void install(File artifact); void tryInstallFailed(); @Override void update(File artifact); @Override void uninstall(final File artifact); void setServiceManager(ConnectorManager serviceManager); void setBundleContext(BundleContext bundleContext);  }
@Test public void testConnectorFile_shouldBeInstalled() throws Exception { File connectorFile = createSampleConnectorFile(); connectorDeployerService.install(connectorFile); NullDomain domainEndpoints = wiringService.getDomainEndpoint(NullDomain.class, "*"); domainEndpoints.nullMethod(42); verify(createdService).nullMethod(42); }
@Test public void testConnectorFileWithArrays_shouldBeInstalled() throws Exception { File connectorFile = temporaryFolder.newFile(TEST_FILE_NAME); FileUtils.writeStringToFile(connectorFile, testConnectorData + "\nproperty.bla=foo,bar"); connectorDeployerService.install(connectorFile); serviceUtils.getService("(bla=foo)", 100L); serviceUtils.getService("(bla=bar)", 100L); }
@Test public void testConnectorFileWithRanking_shouldBeInstalledWithNumericRanking() throws Exception { File connectorFile = temporaryFolder.newFile(TEST_FILE_NAME); FileUtils .writeStringToFile(connectorFile, testConnectorData + "\nproperty.service.ranking=2\nproperty.bla=foo"); connectorDeployerService.install(connectorFile); serviceUtils.getService("(bla=foo)", 100L); ServiceReference serviceReference = bundleContext.getServiceReferences((String) null, "(bla=foo)")[0]; Integer ranking = (Integer) serviceReference.getProperty(Constants.SERVICE_RANKING); assertThat(ranking, notNullValue()); }
@Test public void testConnectorFileWithArraysAndTrailingSpace_shouldBeInstalled() throws Exception { File connectorFile = temporaryFolder.newFile(TEST_FILE_NAME); FileUtils.writeStringToFile(connectorFile, testConnectorData + "\nproperty.bla=foo , bar"); connectorDeployerService.install(connectorFile); serviceUtils.getService("(bla=foo)", 100L); serviceUtils.getService("(bla=bar)", 100L); }
@Test public void testRootService_shouldHaveLowerRanking() throws Exception { File connectorFile = new File(temporaryFolder.getRoot() + "/etc/mydomain+aconnector+myroot.connector"); FileUtils.touch(connectorFile); FileUtils.writeStringToFile(connectorFile, testConnectorData); connectorDeployerService.install(connectorFile); ServiceReference reference = bundleContext.getServiceReferences(NullDomain.class.getName(), "")[0]; Integer ranking = (Integer) reference.getProperty(Constants.SERVICE_RANKING); assertThat(ranking, lessThan(0)); }
@Test public void testNormalService_shouldHaveNoRankingAdded() throws Exception { File connectorFile = new File(temporaryFolder.getRoot() + "/config/mydomain+aconnector+myroot.connector"); FileUtils.touch(connectorFile); FileUtils.writeStringToFile(connectorFile, testConnectorData); connectorDeployerService.install(connectorFile); ServiceReference reference = bundleContext.getServiceReferences(NullDomain.class.getName(), "")[0]; assertThat(reference.getProperty(Constants.SERVICE_RANKING), nullValue()); }
@Test public void testOverridenRanking_shouldNotBeAltered() throws Exception { File connectorFile = new File(temporaryFolder.getRoot() + "/etc/mydomain+aconnector+myroot.connector"); FileUtils.touch(connectorFile); FileUtils.writeStringToFile(connectorFile, testConnectorData + "\n" + "property." + Constants.SERVICE_RANKING + "=24"); connectorDeployerService.install(connectorFile); ServiceReference ref = bundleContext.getServiceReferences(NullDomain.class.getName(), String.format("(%s=%s)", Constants.SERVICE_RANKING, 24))[0]; assertThat(ref, not(nullValue())); }
@Test @Ignore public void testInstallService_shouldNotOverwriteExistingService() throws Exception { Map<String, Object> properties = new Hashtable<String, Object>(); properties.put("foo", "bar"); ConnectorDescription connectorDescription = new ConnectorDescription("mydomain", "aconnector", null, properties); serviceManager.createWithId(testConnectorId, connectorDescription); File connectorFile = createSampleConnectorFile(); connectorDeployerService.install(connectorFile); ServiceReference[] references = bundleContext.getServiceReferences(NullDomain.class.getName(), "(foo=bar)"); assertThat("old service is not there anymore", references, not(nullValue())); }
@Test @Ignore public void testInstallFailure_shouldLeaveFileAsIs() throws Exception { Map<String, Object> properties = new Hashtable<String, Object>(); properties.put("foo", "bar"); ConnectorDescription connectorDescription = new ConnectorDescription("mydomain", "aconnector", new HashMap<String, String>(), properties); serviceManager.createWithId(testConnectorId, connectorDescription); File connectorFile = createSampleConnectorFile(); connectorDeployerService.install(connectorFile); ServiceReference[] references = bundleContext.getServiceReferences(NullDomain.class.getName(), "(foo=bar)"); assertThat(connectorFile.exists(), is(true)); assertThat("old service is not there anymore", references, not(nullValue())); }