incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject svn commit: r1452457 [3/3] - in /incubator/ambari/trunk: ./ ambari-server/src/main/java/org/apache/ambari/server/ ambari-server/src/main/java/org/apache/ambari/server/api/resources/ ambari-server/src/main/java/org/apache/ambari/server/api/services/ amb...
Date Mon, 04 Mar 2013 19:16:30 GMT
Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java?rev=1452457&r1=1452456&r2=1452457&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
Mon Mar  4 19:16:28 2013
@@ -34,9 +34,15 @@ import java.util.Set;
 
 import junit.framework.Assert;
 
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.StackAccessException;
 import org.apache.ambari.server.state.ComponentInfo;
+import org.apache.ambari.server.state.OperatingSystemInfo;
+import org.apache.ambari.server.state.PropertyInfo;
 import org.apache.ambari.server.state.RepositoryInfo;
 import org.apache.ambari.server.state.ServiceInfo;
+import org.apache.ambari.server.state.Stack;
+import org.apache.ambari.server.state.StackInfo;
 import org.apache.commons.io.FileUtils;
 import org.junit.Before;
 import org.junit.Rule;
@@ -51,10 +57,21 @@ public class AmbariMetaInfoTest {
   private static String STACK_VERSION_HDP = "0.1";
   private static String SERVICE_NAME_HDFS = "HDFS";
   private static String SERVICE_COMPONENT_NAME = "NAMENODE";
+  private static final String OS_TYPE = "centos5";
+  private static final String REPO_ID = "HDP-UTILS-1.1.0.15";
+  private static final String PROPERTY_NAME = "hbase.regionserver.msginterval";
+  
+  private static final String NON_EXT_VALUE = "XXX";
+  
+  private static final int REPOS_CNT = 3;
+  private static final int STACKS_NAMES_CNT = 1;
+  private static final int PROPERTIES_CNT = 63;
+  private static final int OS_CNT = 3;
 
   private AmbariMetaInfo metaInfo = null;
   private final static Logger LOG =
       LoggerFactory.getLogger(AmbariMetaInfoTest.class);
+  
 
   @Rule
   public TemporaryFolder tmpFolder = new TemporaryFolder();
@@ -72,7 +89,7 @@ public class AmbariMetaInfoTest {
   }
 
   @Test
-  public void getComponentCategory() {
+  public void getComponentCategory() throws AmbariException {
     ComponentInfo componentInfo = metaInfo.getComponentCategory(STACK_NAME_HDP,
         STACK_VERSION_HDP, SERVICE_NAME_HDFS, SERVICE_COMPONENT_NAME);
     assertNotNull(componentInfo);
@@ -83,14 +100,14 @@ public class AmbariMetaInfoTest {
   }
 
   @Test
-  public void getComponentsByService() {
+  public void getComponentsByService() throws AmbariException {
     List<ComponentInfo> components = metaInfo.getComponentsByService(
         STACK_NAME_HDP, STACK_VERSION_HDP, SERVICE_NAME_HDFS);
     assertNotNull(components);
   }
 
   @Test
-  public void getRepository() {
+  public void getRepository() throws AmbariException {
     Map<String, List<RepositoryInfo>> repository = metaInfo.getRepository(
         STACK_NAME_HDP, STACK_VERSION_HDP);
     assertNotNull(repository);
@@ -99,17 +116,24 @@ public class AmbariMetaInfoTest {
   }
 
   @Test
-  public void isSupportedStack() {
-    boolean supportedStack = metaInfo.isSupportedStack(STACK_VERSION_HDP,
+  public void isSupportedStack() throws AmbariException {
+    boolean supportedStack = metaInfo.isSupportedStack(STACK_NAME_HDP,
         STACK_VERSION_HDP);
     assertTrue(supportedStack);
+    
+    boolean notSupportedStack = metaInfo.isSupportedStack(NON_EXT_VALUE,
+        NON_EXT_VALUE);
+    assertFalse(notSupportedStack);
   }
 
   @Test
-  public void isValidService() {
+  public void isValidService() throws AmbariException {
     boolean valid = metaInfo.isValidService(STACK_NAME_HDP, STACK_VERSION_HDP,
         SERVICE_NAME_HDFS);
     assertTrue(valid);
+
+    boolean invalid = metaInfo.isValidService(STACK_NAME_HDP, NON_EXT_VALUE, NON_EXT_VALUE);
+    assertFalse(invalid);
   }
 
   /**
@@ -131,7 +155,7 @@ public class AmbariMetaInfoTest {
   }
 
   @Test
-  public void testServiceNameUsingComponentName() {
+  public void testServiceNameUsingComponentName() throws AmbariException {
     String serviceName = metaInfo.getComponentToService(STACK_NAME_HDP,
         STACK_VERSION_HDP, "NAMENODE");
     assertTrue("HDFS".equals(serviceName));
@@ -140,9 +164,10 @@ public class AmbariMetaInfoTest {
   /**
    * Method: Map<String, ServiceInfo> getServices(String stackName, String
    * version, String serviceName)
+   * @throws AmbariException 
    */
   @Test
-  public void getServices() {
+  public void getServices() throws AmbariException {
     Map<String, ServiceInfo> services = metaInfo.getServices(STACK_NAME_HDP,
         STACK_VERSION_HDP);
     LOG.info("Getting all the services ");
@@ -236,8 +261,127 @@ public class AmbariMetaInfoTest {
     getSupportedConfigs();
     // Check .svn is not part of the stack but abcd.svn is
     Assert.assertNotNull(ambariMetaInfo.getStackInfo("abcd.svn", "001.svn"));
-    Assert.assertNull(ambariMetaInfo.getStackInfo(".svn", ""));
-    Assert.assertNull(ambariMetaInfo.getServices(".svn", ""));
+    
+    Assert.assertFalse(ambariMetaInfo.isSupportedStack(".svn", ""));
+    Assert.assertFalse(ambariMetaInfo.isSupportedStack(".svn", ""));
+  }
+  
+  
+  @Test
+  public void testGetComponent() throws Exception {
+    ComponentInfo component = metaInfo.getComponent(STACK_NAME_HDP,
+        STACK_VERSION_HDP, SERVICE_NAME_HDFS, SERVICE_COMPONENT_NAME);
+    Assert.assertEquals(component.getName(), SERVICE_COMPONENT_NAME);
+
+    try {
+      metaInfo.getComponent(STACK_NAME_HDP,
+          STACK_VERSION_HDP, SERVICE_NAME_HDFS, NON_EXT_VALUE);
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    }
+    
+  }
+  
+  @Test
+  public void testGetRepositories() throws Exception {
+    List<RepositoryInfo> repositories = metaInfo.getRepositories(STACK_NAME_HDP, STACK_VERSION_HDP,
OS_TYPE);
+    Assert.assertEquals(repositories.size(), REPOS_CNT);
   }
 
+  @Test
+  public void testGetRepository() throws Exception {
+    RepositoryInfo repository = metaInfo.getRepository(STACK_NAME_HDP, STACK_VERSION_HDP,
OS_TYPE, REPO_ID);
+    Assert.assertEquals(repository.getRepoId(), REPO_ID);
+
+    try {
+      metaInfo.getRepository(STACK_NAME_HDP, STACK_VERSION_HDP, OS_TYPE, NON_EXT_VALUE);
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    }
+  }
+  
+  @Test
+  public void testGetService() throws Exception {
+    ServiceInfo service = metaInfo.getService(STACK_NAME_HDP, STACK_VERSION_HDP, SERVICE_NAME_HDFS);
+    Assert.assertEquals(service.getName(), SERVICE_NAME_HDFS);
+    try {
+      metaInfo.getService(STACK_NAME_HDP, STACK_VERSION_HDP, NON_EXT_VALUE);
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    }
+    
+  }
+  
+  @Test
+  public void testGetStacksNames() throws Exception {
+    Set<Stack> stackNames = metaInfo.getStackNames();
+    assertEquals(stackNames.size(), STACKS_NAMES_CNT);
+    assertTrue(stackNames.contains(new Stack(STACK_NAME_HDP)));
+  }
+  
+  @Test
+  public void testGetStack() throws Exception {
+    Stack stack = metaInfo.getStack(STACK_NAME_HDP);
+    Assert.assertEquals(stack.getStackName(), STACK_NAME_HDP);
+    try {
+      metaInfo.getStack(NON_EXT_VALUE);
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    }
+  }
+  
+  
+  @Test
+  public void testGetStackInfo() throws Exception {
+    StackInfo stackInfo = metaInfo.getStackInfo(STACK_NAME_HDP, STACK_VERSION_HDP);
+    Assert.assertEquals(stackInfo.getName(), STACK_NAME_HDP);
+    Assert.assertEquals(stackInfo.getVersion(), STACK_VERSION_HDP);
+    try {
+      metaInfo.getStackInfo(STACK_NAME_HDP, NON_EXT_VALUE);
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    }
+  }
+  
+  
+  @Test
+  public void testGetProperties() throws Exception {
+    Set<PropertyInfo> properties = metaInfo.getProperties(STACK_NAME_HDP, STACK_VERSION_HDP,
SERVICE_NAME_HDFS);
+    Assert.assertEquals(properties.size(), PROPERTIES_CNT);
+  }
+  
+  @Test
+  public void testGetProperty() throws Exception {
+    PropertyInfo property = metaInfo.getProperty(STACK_NAME_HDP, STACK_VERSION_HDP, SERVICE_NAME_HDFS,
PROPERTY_NAME);
+    Assert.assertEquals(property.getName(), PROPERTY_NAME);
+
+    try {
+      metaInfo.getProperty(STACK_NAME_HDP, STACK_VERSION_HDP, SERVICE_NAME_HDFS, NON_EXT_VALUE);
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    }
+    
+  }
+  
+  @Test
+  public void testGetOperatingSystems() throws Exception {
+    Set<OperatingSystemInfo> operatingSystems = metaInfo.getOperatingSystems(STACK_NAME_HDP,
STACK_VERSION_HDP);
+    Assert.assertEquals(operatingSystems.size(), OS_CNT);
+  }
+  
+  @Test
+  public void testGetOperatingSystem() throws Exception {
+    OperatingSystemInfo operatingSystem = metaInfo.getOperatingSystem(STACK_NAME_HDP, STACK_VERSION_HDP,
OS_TYPE);
+    Assert.assertEquals(operatingSystem.getOsType(), OS_TYPE);
+    
+    
+    Throwable ex = null;
+    try {
+      metaInfo.getOperatingSystem(STACK_NAME_HDP, STACK_VERSION_HDP, NON_EXT_VALUE);
+    } catch (StackAccessException e) {
+      ex = e;
+    }
+    Assert.assertTrue(ex instanceof StackAccessException);
+  }
+  
 }

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/StacksServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/StacksServiceTest.java?rev=1452457&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/StacksServiceTest.java
(added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/StacksServiceTest.java
Mon Mar  4 19:16:28 2013
@@ -0,0 +1,504 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services;
+
+import org.apache.ambari.server.api.handlers.RequestHandler;
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.junit.Test;
+
+import javax.ws.rs.core.Response;
+
+/**
+ * Unit tests for StacksService.
+ */
+public class StacksServiceTest extends BaseServiceTest {
+
+  private static final String STACK_NAME = "stackName";
+  private static final String STACK_VERSION = "stackVersion";
+  private static final String OS_TYPE = "osType";
+  private static final String REPO_ID = "repoId";
+  private static final String SERVICE_NAME = "serviceName";
+  private static final String PROPERTY_NAME = "propertyName";
+  private static final String COMPONENT_NAME = "componentName";
+
+  @Test
+  public void testGetStacks() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getStacks(getHttpHeaders(), getUriInfo());
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetStacks__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getStacks(getHttpHeaders(), getUriInfo());
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetStack() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getStack(getHttpHeaders(), getUriInfo(),
+        STACK_NAME);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetStack__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getStack(getHttpHeaders(), getUriInfo(),
+        STACK_NAME);
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetStackVersion() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+
+    Response response = stacksService.getStackVersion(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetStackVersion__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getStackVersion(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION);
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetStackVersions() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+
+    Response response = stacksService.getStackVersions(getHttpHeaders(),
+        getUriInfo(), STACK_NAME);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetStackVersions__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getStackVersions(getHttpHeaders(),
+        getUriInfo(), STACK_NAME);
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetRepositories() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+
+    Response response = stacksService.getRepositories(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_NAME, OS_TYPE);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetRepositories__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getRepositories(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, OS_TYPE);
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetRepository() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+
+    Response response = stacksService.getRepository(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_NAME, OS_TYPE, REPO_ID);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetRepository__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getRepository(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetStackServices() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+
+    Response response = stacksService.getStackServices(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetStackServices__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getStackServices(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION);
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetStackService() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+
+    Response response = stacksService.getStackService(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, SERVICE_NAME);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetStackService__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getStackService(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, SERVICE_NAME);
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetStackConfigurations() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+
+    Response response = stacksService.getStackConfigurations(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, SERVICE_NAME);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetStackConfigurations__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getStackConfigurations(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, SERVICE_NAME);
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetStackConfiguration() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+
+    Response response = stacksService.getStackConfiguration(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, SERVICE_NAME, PROPERTY_NAME);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetStackConfiguration__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getStackConfiguration(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, SERVICE_NAME, PROPERTY_NAME);
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetServiceComponent() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+
+    Response response = stacksService.getServiceComponent(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, SERVICE_NAME, COMPONENT_NAME);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetServiceComponent__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getServiceComponent(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, SERVICE_NAME, COMPONENT_NAME);
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetServiceComponents() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+
+    Response response = stacksService.getStackConfiguration(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, SERVICE_NAME, PROPERTY_NAME);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetServiceComponents__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getStackConfiguration(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, SERVICE_NAME, PROPERTY_NAME);
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetOperatingSystems() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+
+    Response response = stacksService.getOperatingSystems(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetOperatingSystems__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getOperatingSystems(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION);
+    verifyResults(response, 500);
+  }
+
+  @Test
+  public void testGetOperatingSystem() {
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+
+    Response response = stacksService.getOperatingSystem(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, OS_TYPE);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetOperatingSystem__ErrorState() {
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    // test
+    StacksService stacksService = new TestStacksService(getResource(),
+        getRequestFactory(), getRequestHandler());
+    Response response = stacksService.getOperatingSystem(getHttpHeaders(),
+        getUriInfo(), STACK_NAME, STACK_VERSION, OS_TYPE);
+    verifyResults(response, 500);
+  }
+
+  private class TestStacksService extends StacksService {
+    private RequestFactory m_requestFactory;
+    private RequestHandler m_requestHandler;
+    private ResourceInstance m_resourceDef;
+
+    private TestStacksService(ResourceInstance resourceDef,
+        RequestFactory requestFactory, RequestHandler handler) {
+      m_resourceDef = resourceDef;
+      m_requestFactory = requestFactory;
+      m_requestHandler = handler;
+    }
+
+    @Override
+    ResourceInstance createStackResource(String stackName) {
+      return m_resourceDef;
+    }
+
+    @Override
+    ResourceInstance createStackVersionResource(String stackName,
+        String stackVersion) {
+      return m_resourceDef;
+    }
+
+    @Override
+    ResourceInstance createRepositoryResource(String stackName,
+        String stackVersion, String osType, String repoId) {
+      return m_resourceDef;
+    }
+
+    @Override
+    ResourceInstance createStackServiceResource(String stackName,
+        String stackVersion, String serviceName) {
+      return m_resourceDef;
+    }
+
+    ResourceInstance createStackConfigurationResource(String stackName,
+        String stackVersion, String serviceName, String propertyName) {
+      return m_resourceDef;
+    }
+
+    ResourceInstance createStackServiceComponentResource(String stackName,
+        String stackVersion, String serviceName, String componentName) {
+      return m_resourceDef;
+    }
+
+    ResourceInstance createOperatingSystemResource(String stackName,
+        String stackVersion, String osType) {
+      return m_resourceDef;
+    }
+
+    @Override
+    RequestFactory getRequestFactory() {
+      return m_requestFactory;
+    }
+
+    @Override
+    RequestHandler getRequestHandler(Request.Type requestType) {
+      return m_requestHandler;
+    }
+  }
+
+  // todo: test getHostHandler, getServiceHandler, getHostComponentHandler
+}

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java?rev=1452457&r1=1452456&r2=1452457&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
Mon Mar  4 19:16:28 2013
@@ -30,15 +30,8 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-
 import junit.framework.Assert;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.ClusterNotFoundException;
-import org.apache.ambari.server.DuplicateResourceException;
-import org.apache.ambari.server.ParentObjectNotFoundException;
-import org.apache.ambari.server.Role;
-import org.apache.ambari.server.RoleCommand;
+import org.apache.ambari.server.*;
 import org.apache.ambari.server.actionmanager.ActionDBAccessor;
 import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
@@ -82,6 +75,25 @@ public class AmbariManagementControllerT
   private static final Logger LOG =
       LoggerFactory.getLogger(AmbariManagementControllerTest.class);
 
+  private static final String STACK_NAME = "HDP";
+
+  private static final String STACK_VERSION = "0.2";
+  private static final String OS_TYPE = "centos5";
+  private static final String REPO_ID = "HDP-1.1.1.16";
+  private static final String PROPERTY_NAME = "hbase.regionserver.msginterval";
+  private static final String SERVICE_NAME = "HDFS";
+  private static final int STACK_VERSIONS_CNT = 2;
+  private static final int REPOS_CNT = 3;
+  private static final int STACKS_CNT = 1;
+  private static final int STACK_SERVICES_CNT = 5 ;
+  private static final int STACK_PROPERTIES_CNT = 63;
+  private static final int STACK_COMPONENTS_CNT = 3;
+  private static final int OS_CNT = 2;
+
+  private static final String NON_EXT_VALUE = "XXX";
+
+  private static final String COMPONENT_NAME = "NAMENODE";
+
   private AmbariManagementController controller;
   private Clusters clusters;
   private ActionDBAccessor actionDB;
@@ -447,7 +459,7 @@ public class AmbariManagementControllerT
       set1.add(valid2);
       controller.createServices(set1);
       fail("Expected failure for invalid services");
-    } catch (IllegalArgumentException e) {
+    } catch (DuplicateResourceException e) {
       // Expected
     }
 
@@ -3782,6 +3794,190 @@ public class AmbariManagementControllerT
     Assert.assertEquals(Role.PIG_SERVICE_CHECK.toString(),
         taskStatuses.get(0).getRole());
   }
+  
+  
+  @Test
+  public void testGetStacks() throws Exception {
+    
+
+    StackRequest request = new StackRequest(null);
+    Set<StackResponse> responses = controller.getStacks(Collections.singleton(request));
+    Assert.assertEquals(STACKS_CNT, responses.size());
+    
+    StackRequest requestWithParams = new StackRequest(STACK_NAME);
+    Set<StackResponse> responsesWithParams = controller.getStacks(Collections.singleton(requestWithParams));
+    Assert.assertEquals(1, responsesWithParams.size());
+    for (StackResponse responseWithParams: responsesWithParams) {
+      Assert.assertEquals(responseWithParams.getStackName(), STACK_NAME);
+      
+    }
+    
+    StackRequest invalidRequest = new StackRequest(NON_EXT_VALUE);
+    try {
+      controller.getStacks(Collections.singleton(invalidRequest));
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    }
+  }
+  
+  @Test
+  public void testGetStackVersions() throws Exception {
+    
+
+    StackVersionRequest request = new StackVersionRequest(STACK_NAME, null);
+    Set<StackVersionResponse> responses = controller.getStackVersions(Collections.singleton(request));
+    Assert.assertEquals(STACK_VERSIONS_CNT, responses.size());
+    
+    StackVersionRequest requestWithParams = new StackVersionRequest(STACK_NAME, STACK_VERSION);
+    Set<StackVersionResponse> responsesWithParams = controller.getStackVersions(Collections.singleton(requestWithParams));
+    Assert.assertEquals(1, responsesWithParams.size());
+    for (StackVersionResponse responseWithParams: responsesWithParams) {
+      Assert.assertEquals(responseWithParams.getStackVersion(), STACK_VERSION);
+      
+    }
+    
+    StackVersionRequest invalidRequest = new StackVersionRequest(STACK_NAME, NON_EXT_VALUE);
+    try {
+      controller.getStackVersions(Collections.singleton(invalidRequest));
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    } 
+  }
+  
+
+  @Test
+  public void testGetRepositories() throws Exception {
+    
+    RepositoryRequest request = new RepositoryRequest(STACK_NAME, STACK_VERSION, OS_TYPE,
null);
+    Set<RepositoryResponse> responses = controller.getRepositories(Collections.singleton(request));
+    Assert.assertEquals(REPOS_CNT, responses.size());
+    
+    RepositoryRequest requestWithParams = new RepositoryRequest(STACK_NAME, STACK_VERSION,
OS_TYPE, REPO_ID);
+    Set<RepositoryResponse> responsesWithParams = controller.getRepositories(Collections.singleton(requestWithParams));
+    Assert.assertEquals(1, responsesWithParams.size());
+    for (RepositoryResponse responseWithParams: responsesWithParams) {
+      Assert.assertEquals(responseWithParams.getRepoId(), REPO_ID);
+      
+    }
+    
+    RepositoryRequest invalidRequest = new RepositoryRequest(STACK_NAME, STACK_VERSION, OS_TYPE,
NON_EXT_VALUE);
+    try {
+      controller.getRepositories(Collections.singleton(invalidRequest));
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    }
+  }
+  
+  
+  @Test
+  public void testGetStackServices() throws Exception {
+    
+
+    StackServiceRequest request = new StackServiceRequest(STACK_NAME, STACK_VERSION, null);
+    Set<StackServiceResponse> responses = controller.getStackServices(Collections.singleton(request));
+    Assert.assertEquals(STACK_SERVICES_CNT, responses.size());
+    
+    
+    StackServiceRequest requestWithParams = new StackServiceRequest(STACK_NAME, STACK_VERSION,
SERVICE_NAME);
+    Set<StackServiceResponse> responsesWithParams = controller.getStackServices(Collections.singleton(requestWithParams));
+    Assert.assertEquals(1, responsesWithParams.size());
+    for (StackServiceResponse responseWithParams: responsesWithParams) {
+      Assert.assertEquals(responseWithParams.getServiceName(), SERVICE_NAME);
+      
+    }
+    
+    StackServiceRequest invalidRequest = new StackServiceRequest(STACK_NAME, STACK_VERSION,
NON_EXT_VALUE);
+    try {
+      controller.getStackServices(Collections.singleton(invalidRequest));
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    }
+    
+    
+  }
+  
+  @Test
+  public void testGetStackConfigurations() throws Exception {
+    
+
+    StackConfigurationRequest request = new StackConfigurationRequest(STACK_NAME, STACK_VERSION,
SERVICE_NAME, null);
+    Set<StackConfigurationResponse> responses = controller.getStackConfigurations(Collections.singleton(request));
+    Assert.assertEquals(STACK_PROPERTIES_CNT, responses.size());
+    
+    
+    StackConfigurationRequest requestWithParams = new StackConfigurationRequest(STACK_NAME,
STACK_VERSION, SERVICE_NAME, PROPERTY_NAME);
+    Set<StackConfigurationResponse> responsesWithParams = controller.getStackConfigurations(Collections.singleton(requestWithParams));
+    Assert.assertEquals(1, responsesWithParams.size());
+    for (StackConfigurationResponse responseWithParams: responsesWithParams) {
+      Assert.assertEquals(responseWithParams.getPropertyName(), PROPERTY_NAME);
+      
+    }
+    
+    StackConfigurationRequest invalidRequest = new StackConfigurationRequest(STACK_NAME,
STACK_VERSION, SERVICE_NAME, NON_EXT_VALUE);
+    try {
+      controller.getStackConfigurations(Collections.singleton(invalidRequest));
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    }
+  }
+  
+  
+  @Test
+  public void testGetStackComponents() throws Exception {
+    
+
+    StackServiceComponentRequest request = new StackServiceComponentRequest(STACK_NAME, STACK_VERSION,
SERVICE_NAME, null);
+    Set<StackServiceComponentResponse> responses = controller.getStackComponents(Collections.singleton(request));
+    Assert.assertEquals(STACK_COMPONENTS_CNT, responses.size());
+    
+    
+    StackServiceComponentRequest requestWithParams = new StackServiceComponentRequest(STACK_NAME,
STACK_VERSION, SERVICE_NAME, COMPONENT_NAME);
+    Set<StackServiceComponentResponse> responsesWithParams = controller.getStackComponents(Collections.singleton(requestWithParams));
+    Assert.assertEquals(1, responsesWithParams.size());
+    for (StackServiceComponentResponse responseWithParams: responsesWithParams) {
+      Assert.assertEquals(responseWithParams.getComponentName(), COMPONENT_NAME);
+      
+    }
+    
+    StackServiceComponentRequest invalidRequest = new StackServiceComponentRequest(STACK_NAME,
STACK_VERSION, SERVICE_NAME, NON_EXT_VALUE);
+    try {
+      controller.getStackComponents(Collections.singleton(invalidRequest));
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    }
+    
+    
+  }
+  
+  @Test
+  public void testGetStackOperatingSystems() throws Exception {
+    
+
+    OperatingSystemRequest request = new OperatingSystemRequest(STACK_NAME, STACK_VERSION,
null);
+    Set<OperatingSystemResponse> responses = controller.getStackOperatingSystems(Collections.singleton(request));
+    Assert.assertEquals(OS_CNT, responses.size());
+    
+    
+    OperatingSystemRequest requestWithParams = new OperatingSystemRequest(STACK_NAME, STACK_VERSION,
OS_TYPE);
+    Set<OperatingSystemResponse> responsesWithParams = controller.getStackOperatingSystems(Collections.singleton(requestWithParams));
+    Assert.assertEquals(1, responsesWithParams.size());
+    for (OperatingSystemResponse responseWithParams: responsesWithParams) {
+      Assert.assertEquals(responseWithParams.getOsType(), OS_TYPE);
+      
+    }
+    
+    OperatingSystemRequest invalidRequest = new OperatingSystemRequest(STACK_NAME, STACK_VERSION,
NON_EXT_VALUE);
+    try {
+      controller.getStackOperatingSystems(Collections.singleton(invalidRequest));
+    } catch (StackAccessException e) {
+      Assert.assertTrue(e instanceof StackAccessException);
+    }
+    
+    
+  }
+  
+  
+  
 
   @Test
   public void testUpdateClusterVersionBasic() throws AmbariException {



Mime
View raw message