|
@@ -18,11 +18,14 @@
|
|
|
|
|
|
package org.apache.ambari.server.controller;
|
|
package org.apache.ambari.server.controller;
|
|
|
|
|
|
|
|
+import static junit.framework.Assert.assertEquals;
|
|
|
|
+import static junit.framework.Assert.assertTrue;
|
|
|
|
+
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
|
import org.apache.ambari.server.ObjectNotFoundException;
|
|
import org.apache.ambari.server.ObjectNotFoundException;
|
|
-import org.apache.ambari.server.configuration.Configuration;
|
|
|
|
|
|
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
|
|
import org.apache.ambari.server.controller.RootServiceResponseFactory.Components;
|
|
import org.apache.ambari.server.controller.RootServiceResponseFactory.Components;
|
|
import org.apache.ambari.server.orm.GuiceJpaInitializer;
|
|
import org.apache.ambari.server.orm.GuiceJpaInitializer;
|
|
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
|
|
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
|
|
@@ -33,21 +36,17 @@ import com.google.inject.Guice;
|
|
import com.google.inject.Inject;
|
|
import com.google.inject.Inject;
|
|
import com.google.inject.Injector;
|
|
import com.google.inject.Injector;
|
|
|
|
|
|
-import static junit.framework.Assert.assertTrue;
|
|
|
|
-import static junit.framework.Assert.assertEquals;
|
|
|
|
-
|
|
|
|
public class RootServiceResponseFactoryTest {
|
|
public class RootServiceResponseFactoryTest {
|
|
|
|
|
|
@Inject
|
|
@Inject
|
|
private RootServiceResponseFactory responseFactory;
|
|
private RootServiceResponseFactory responseFactory;
|
|
private Injector injector;
|
|
private Injector injector;
|
|
-
|
|
|
|
|
|
+
|
|
@Inject
|
|
@Inject
|
|
- Configuration configs;
|
|
|
|
|
|
+ private AmbariMetaInfo ambariMetaInfo;
|
|
|
|
|
|
-
|
|
|
|
@Before
|
|
@Before
|
|
- public void setUp() throws Exception{
|
|
|
|
|
|
+ public void setUp() throws Exception {
|
|
injector = Guice.createInjector(new InMemoryDefaultTestModule());
|
|
injector = Guice.createInjector(new InMemoryDefaultTestModule());
|
|
injector.getInstance(GuiceJpaInitializer.class);
|
|
injector.getInstance(GuiceJpaInitializer.class);
|
|
injector.injectMembers(this);
|
|
injector.injectMembers(this);
|
|
@@ -55,11 +54,9 @@ public class RootServiceResponseFactoryTest {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testGetRootServices() throws Exception {
|
|
public void testGetRootServices() throws Exception {
|
|
-
|
|
|
|
// Request a null service name
|
|
// Request a null service name
|
|
RootServiceRequest request = new RootServiceRequest(null);
|
|
RootServiceRequest request = new RootServiceRequest(null);
|
|
- Set<RootServiceResponse> rootServices =
|
|
|
|
- responseFactory.getRootServices(request);
|
|
|
|
|
|
+ Set<RootServiceResponse> rootServices = responseFactory.getRootServices(request);
|
|
assertEquals(RootServiceResponseFactory.Services.values().length,
|
|
assertEquals(RootServiceResponseFactory.Services.values().length,
|
|
rootServices.size());
|
|
rootServices.size());
|
|
|
|
|
|
@@ -72,17 +69,15 @@ public class RootServiceResponseFactoryTest {
|
|
// Request nonexistent service
|
|
// Request nonexistent service
|
|
try {
|
|
try {
|
|
request = new RootServiceRequest("XXX");
|
|
request = new RootServiceRequest("XXX");
|
|
- ;
|
|
|
|
rootServices = responseFactory.getRootServices(request);
|
|
rootServices = responseFactory.getRootServices(request);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
assertTrue(e instanceof ObjectNotFoundException);
|
|
assertTrue(e instanceof ObjectNotFoundException);
|
|
}
|
|
}
|
|
|
|
|
|
// Request existent service
|
|
// Request existent service
|
|
- request =
|
|
|
|
- new RootServiceRequest(
|
|
|
|
- RootServiceResponseFactory.Services.AMBARI.name());
|
|
|
|
- ;
|
|
|
|
|
|
+ request = new RootServiceRequest(
|
|
|
|
+ RootServiceResponseFactory.Services.AMBARI.name());
|
|
|
|
+
|
|
rootServices = responseFactory.getRootServices(request);
|
|
rootServices = responseFactory.getRootServices(request);
|
|
assertEquals(1, rootServices.size());
|
|
assertEquals(1, rootServices.size());
|
|
assertTrue(rootServices.contains(new RootServiceResponse(
|
|
assertTrue(rootServices.contains(new RootServiceResponse(
|
|
@@ -91,10 +86,10 @@ public class RootServiceResponseFactoryTest {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testGetRootServiceComponents() throws Exception {
|
|
public void testGetRootServiceComponents() throws Exception {
|
|
-
|
|
|
|
// Request null service name, null component name
|
|
// Request null service name, null component name
|
|
- RootServiceComponentRequest request =
|
|
|
|
- new RootServiceComponentRequest(null, null);
|
|
|
|
|
|
+ RootServiceComponentRequest request = new RootServiceComponentRequest(null,
|
|
|
|
+ null);
|
|
|
|
+
|
|
Set<RootServiceComponentResponse> rootServiceComponents;
|
|
Set<RootServiceComponentResponse> rootServiceComponents;
|
|
try {
|
|
try {
|
|
rootServiceComponents = responseFactory.getRootServiceComponents(request);
|
|
rootServiceComponents = responseFactory.getRootServiceComponents(request);
|
|
@@ -102,10 +97,11 @@ public class RootServiceResponseFactoryTest {
|
|
assertTrue(e instanceof ObjectNotFoundException);
|
|
assertTrue(e instanceof ObjectNotFoundException);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ RootServiceResponseFactory.Components ambariServerComponent = RootServiceResponseFactory.Components.AMBARI_SERVER;
|
|
|
|
+
|
|
// Request null service name, not-null component name
|
|
// Request null service name, not-null component name
|
|
- request =
|
|
|
|
- new RootServiceComponentRequest(null,
|
|
|
|
- RootServiceResponseFactory.Components.AMBARI_SERVER.name());
|
|
|
|
|
|
+ request = new RootServiceComponentRequest(null,
|
|
|
|
+ ambariServerComponent.name());
|
|
|
|
|
|
try {
|
|
try {
|
|
rootServiceComponents = responseFactory.getRootServiceComponents(request);
|
|
rootServiceComponents = responseFactory.getRootServiceComponents(request);
|
|
@@ -114,59 +110,55 @@ public class RootServiceResponseFactoryTest {
|
|
}
|
|
}
|
|
|
|
|
|
// Request existent service name, null component name
|
|
// Request existent service name, null component name
|
|
- request =
|
|
|
|
- new RootServiceComponentRequest(
|
|
|
|
- RootServiceResponseFactory.Services.AMBARI.name(), null);
|
|
|
|
|
|
+ request = new RootServiceComponentRequest(
|
|
|
|
+ RootServiceResponseFactory.Services.AMBARI.name(), null);
|
|
|
|
+
|
|
rootServiceComponents = responseFactory.getRootServiceComponents(request);
|
|
rootServiceComponents = responseFactory.getRootServiceComponents(request);
|
|
assertEquals(
|
|
assertEquals(
|
|
RootServiceResponseFactory.Services.AMBARI.getComponents().length,
|
|
RootServiceResponseFactory.Services.AMBARI.getComponents().length,
|
|
rootServiceComponents.size());
|
|
rootServiceComponents.size());
|
|
|
|
|
|
- for (int i = 0; i < RootServiceResponseFactory.Services.AMBARI
|
|
|
|
- .getComponents().length; i++) {
|
|
|
|
- Components component =
|
|
|
|
- RootServiceResponseFactory.Services.AMBARI.getComponents()[i];
|
|
|
|
-
|
|
|
|
- if (component.name().equals(
|
|
|
|
- RootServiceResponseFactory.Components.AMBARI_SERVER.name())) {
|
|
|
|
- for (RootServiceComponentResponse response : rootServiceComponents) {
|
|
|
|
- if (response.getComponentName().equals(RootServiceResponseFactory.Components.AMBARI_SERVER.name())) {
|
|
|
|
- assertEquals(response.getComponentVersion(), "1.3.0");
|
|
|
|
- assertEquals(response.getProperties().size(), 1);
|
|
|
|
- assertTrue(response.getProperties().containsKey("jdk_location"));
|
|
|
|
- //assertEquals(response.getProperties().get("jdk_location"), "http://localhost:8080/resources/");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ String ambariVersion = ambariMetaInfo.getServerVersion();
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < RootServiceResponseFactory.Services.AMBARI.getComponents().length; i++) {
|
|
|
|
+ Components component = RootServiceResponseFactory.Services.AMBARI.getComponents()[i];
|
|
|
|
+
|
|
|
|
+ if (component.name().equals(ambariServerComponent.name())) {
|
|
|
|
+ for (RootServiceComponentResponse response : rootServiceComponents) {
|
|
|
|
+ if (response.getComponentName().equals(ambariServerComponent.name())) {
|
|
|
|
+ assertEquals(ambariVersion, response.getComponentVersion());
|
|
|
|
+ assertEquals(1, response.getProperties().size(), 1);
|
|
|
|
+ assertTrue(response.getProperties().containsKey("jdk_location"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- assertTrue(rootServiceComponents
|
|
|
|
- .contains(new RootServiceComponentResponse(component.name(),
|
|
|
|
- RootServiceResponseFactory.NOT_APPLICABLE,
|
|
|
|
- Collections.<String, String> emptyMap())));
|
|
|
|
|
|
+ assertTrue(rootServiceComponents.contains(new RootServiceComponentResponse(
|
|
|
|
+ component.name(), RootServiceResponseFactory.NOT_APPLICABLE,
|
|
|
|
+ Collections.<String, String> emptyMap())));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Request existent service name, existent component name
|
|
// Request existent service name, existent component name
|
|
- request =
|
|
|
|
- new RootServiceComponentRequest(
|
|
|
|
- RootServiceResponseFactory.Services.AMBARI.name(),
|
|
|
|
- RootServiceResponseFactory.Services.AMBARI.getComponents()[0]
|
|
|
|
- .name());
|
|
|
|
|
|
+ request = new RootServiceComponentRequest(
|
|
|
|
+ RootServiceResponseFactory.Services.AMBARI.name(),
|
|
|
|
+ RootServiceResponseFactory.Services.AMBARI.getComponents()[0].name());
|
|
|
|
+
|
|
rootServiceComponents = responseFactory.getRootServiceComponents(request);
|
|
rootServiceComponents = responseFactory.getRootServiceComponents(request);
|
|
assertEquals(1, rootServiceComponents.size());
|
|
assertEquals(1, rootServiceComponents.size());
|
|
for (RootServiceComponentResponse response : rootServiceComponents) {
|
|
for (RootServiceComponentResponse response : rootServiceComponents) {
|
|
- if (response.getComponentName().equals(RootServiceResponseFactory.Services.AMBARI.getComponents()[0].name())) {
|
|
|
|
- assertEquals(response.getComponentVersion(), "1.3.0");
|
|
|
|
- assertEquals(response.getProperties().size(), 1);
|
|
|
|
|
|
+ if (response.getComponentName().equals(
|
|
|
|
+ RootServiceResponseFactory.Services.AMBARI.getComponents()[0].name())) {
|
|
|
|
+ assertEquals(ambariVersion, response.getComponentVersion());
|
|
|
|
+ assertEquals(1, response.getProperties().size());
|
|
assertTrue(response.getProperties().containsKey("jdk_location"));
|
|
assertTrue(response.getProperties().containsKey("jdk_location"));
|
|
- //assertEquals(response.getProperties().get("jdk_location"), "http://localhost:8080/resources/");
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Request existent service name, and component, not belongs to requested
|
|
|
|
+ // service
|
|
|
|
+ request = new RootServiceComponentRequest(
|
|
|
|
+ RootServiceResponseFactory.Services.AMBARI.name(), "XXX");
|
|
|
|
|
|
- // Request existent service name, and component, not belongs to requested service
|
|
|
|
- request =
|
|
|
|
- new RootServiceComponentRequest(
|
|
|
|
- RootServiceResponseFactory.Services.AMBARI.name(),
|
|
|
|
- "XXX");
|
|
|
|
try {
|
|
try {
|
|
rootServiceComponents = responseFactory.getRootServiceComponents(request);
|
|
rootServiceComponents = responseFactory.getRootServiceComponents(request);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|