injector.getInstance(GuiceJpaInitializer.class);
try {
String tag = "version1";
String type = "core-site";
AmbariException exception = null;
try {
AmbariManagementController amc = injector.getInstance(AmbariManagementController.class);
Clusters clusters = injector.getInstance(Clusters.class);
Gson gson = new Gson();
clusters.addHost("host1");
clusters.addHost("host2");
clusters.addHost("host3");
Host host = clusters.getHost("host1");
host.setOsType("centos6");
host.persist();
host = clusters.getHost("host2");
host.setOsType("centos6");
host.persist();
host = clusters.getHost("host3");
host.setOsType("centos6");
host.persist();
ClusterRequest clusterRequest = new ClusterRequest(null, "c1", "HDP-1.2.0", null);
amc.createCluster(clusterRequest);
Set<ServiceRequest> serviceRequests = new HashSet<ServiceRequest>();
serviceRequests.add(new ServiceRequest("c1", "HDFS", null));
ServiceResourceProviderTest.createServices(amc, serviceRequests);
Type confType = new TypeToken<Map<String, String>>() {
}.getType();
ConfigurationRequest configurationRequest = new ConfigurationRequest("c1", type, tag,
gson.<Map<String, String>>fromJson("{ \"fs.default.name\" : \"localhost:8020\"}", confType));
amc.createConfiguration(configurationRequest);
amc.createConfiguration(configurationRequest);
} catch (AmbariException e) {
exception = e;
}
assertNotNull(exception);
String exceptionMessage = MessageFormat.format("Configuration with tag ''{0}'' exists for ''{1}''",
tag, type);
org.junit.Assert.assertEquals(exceptionMessage, exception.getMessage());
} finally {
injector.getInstance(PersistService.class).stop();
}
}