DeviceTypePluginDeployer extends AbstractDeployer { @Override public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException { try { DeviceTypeConfiguration deviceTypeConfiguration = getDeviceTypeConfiguration( deploymentFileData.getFile().getAbsoluteFile()); String deviceType = deviceTypeConfiguration.getName(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); if (deviceType != null && !deviceType.isEmpty() && tenantDomain != null && !tenantDomain.isEmpty()) { DeviceTypeConfigIdentifier deviceTypeConfigIdentifier = new DeviceTypeConfigIdentifier(deviceType, tenantDomain); ServiceRegistration serviceRegistration = registerDeviceType(deviceTypeConfigIdentifier, deviceTypeConfiguration); this.deviceTypeServiceRegistrations.put(deploymentFileData.getAbsolutePath(), serviceRegistration); this.deviceTypeConfigurationDataMap.put(deploymentFileData.getAbsolutePath(), deviceTypeConfigIdentifier); } } catch (Throwable e) { log.error("Cannot deploy deviceType : " + deploymentFileData.getName(), e); throw new DeploymentException("Device type file " + deploymentFileData.getName() + " is not deployed ", e); } }  @Override void init(ConfigurationContext configurationContext); @Override void setDirectory(String s); @Override void setExtension(String s); @Override void deploy(DeploymentFileData deploymentFileData); @Override void undeploy(String filePath);  }
@SuppressWarnings("unchecked") @Test(description = "Testing deviceType deploy method by deploying Android device type") public void deploy() throws DeploymentException, IllegalAccessException { deviceTypePluginDeployer.deploy(deploymentFileData); Map<String, ServiceRegistration> tempServiceRegistration = (Map<String, ServiceRegistration>) deviceTypeServiceRegistrations.get(deviceTypePluginDeployer); Assert.assertEquals(tempServiceRegistration.get(deploymentFileData.getAbsolutePath()), serviceRegistration); Map<String, DeviceTypeConfigIdentifier> tempDeviceTypeConfig = (Map<String, DeviceTypeConfigIdentifier>) deviceTypeConfigurationDataMap.get(deviceTypePluginDeployer); DeviceTypeConfigIdentifier deviceTypeConfigIdentifier = tempDeviceTypeConfig.get(deploymentFileData .getAbsolutePath()); Assert.assertEquals(deviceTypeConfigIdentifier.getDeviceType(), "android"); }
@Test(description = "Testing exception for invalid xml files", expectedExceptions = {org.apache.axis2.deployment .DeploymentException.class}) public void deployInvalidXml() throws DeploymentException, IllegalAccessException { deviceTypePluginDeployer.deploy(invalidDeploymentFileData); }
@Test(description = "Testing exception for non existing xml file", expectedExceptions = {org.apache.axis2.deployment .DeploymentException.class}) public void unDeployInvalidXml() throws DeploymentException, IllegalAccessException { deviceTypePluginDeployer.deploy(new DeploymentFileData(new File("src/test/resources/notExist.xml"))); }