AMBARI-22227 : Unit tests for Registry (mradhakrishnan)

Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a5d0f0c3
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a5d0f0c3
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a5d0f0c3

Branch: refs/heads/branch-feature-AMBARI-14714-ui
Commit: a5d0f0c34f210644e8a854e20c20a962e5d7d70d
Parents: cbaa88d
Author: Madhuvanthi Radhakrishnan <mradhakrish...@hortonworks.com>
Authored: Thu Oct 12 17:21:39 2017 -0700
Committer: Madhuvanthi Radhakrishnan <mradhakrish...@hortonworks.com>
Committed: Thu Oct 12 17:22:32 2017 -0700

----------------------------------------------------------------------
 ...tryRecommendationResourceDefinitionTest.java | 37 ++++++++
 .../RegistryResourceDefinitionTest.java         | 62 +++++++++++++
 ...egistryValidationResourceDefinitionTest.java | 37 ++++++++
 .../api/services/RegistryServiceTest.java       | 94 ++++++++++++++++++++
 .../server/controller/RegistryRequestTest.java  | 37 ++++++++
 5 files changed, 267 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a5d0f0c3/ambari-server/src/test/java/org/apache/ambari/server/api/resources/RegistryRecommendationResourceDefinitionTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/RegistryRecommendationResourceDefinitionTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/RegistryRecommendationResourceDefinitionTest.java
new file mode 100644
index 0000000..335126c
--- /dev/null
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/RegistryRecommendationResourceDefinitionTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.resources;
+
+import static junit.framework.Assert.assertEquals;
+
+import org.junit.Test;
+
+
+
+/**
+ * Test Class for RegistryRecommendationResourceDefinition
+ */
+public class RegistryRecommendationResourceDefinitionTest {
+
+  @Test
+  public void testDefinitionNames() {
+    ResourceDefinition def = new RegistryRecommendationResourceDefinition();
+    assertEquals("recommendation", def.getSingularName());
+    assertEquals("recommendations", def.getPluralName());
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a5d0f0c3/ambari-server/src/test/java/org/apache/ambari/server/api/resources/RegistryResourceDefinitionTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/RegistryResourceDefinitionTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/RegistryResourceDefinitionTest.java
new file mode 100644
index 0000000..145b09d
--- /dev/null
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/RegistryResourceDefinitionTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.resources;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.apache.ambari.server.controller.spi.Resource;
+
+import org.junit.Test;
+
+/**
+ * Test class for RegistryResourceDefinition
+ */
+public class RegistryResourceDefinitionTest {
+  @Test
+  public void testDefinitionNames() {
+    ResourceDefinition def = new RegistryResourceDefinition();
+    assertEquals("registry", def.getSingularName());
+    assertEquals("registries", def.getPluralName());
+  }
+
+  @Test
+  public void testGetSubResourceDefinitions() {
+    ResourceDefinition resource = new RegistryResourceDefinition();
+    Set<SubResourceDefinition> subResources = 
resource.getSubResourceDefinitions();
+
+    assertEquals(2, subResources.size());
+    assertTrue(includesType(subResources, Resource.Type.RegistryScenario));
+    assertTrue(includesType(subResources, Resource.Type.RegistryMpack));
+
+  }
+
+  private boolean includesType(Set<SubResourceDefinition> resources, 
Resource.Type type) {
+    for (SubResourceDefinition subResource : resources) {
+      if (subResource.getType() == type) {
+        return true;
+      }
+    }
+
+    return false;
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a5d0f0c3/ambari-server/src/test/java/org/apache/ambari/server/api/resources/RegistryValidationResourceDefinitionTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/RegistryValidationResourceDefinitionTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/RegistryValidationResourceDefinitionTest.java
new file mode 100644
index 0000000..322a827
--- /dev/null
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/RegistryValidationResourceDefinitionTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.resources;
+
+import static junit.framework.Assert.assertEquals;
+
+import org.junit.Test;
+
+
+
+
+/**
+ * Test class for RegistryValidationResourceDefinition
+ */
+public class RegistryValidationResourceDefinitionTest {
+  @Test
+  public void testDefinitionNames() {
+    ResourceDefinition def = new RegistryValidationResourceDefinition();
+    assertEquals("validation", def.getSingularName());
+    assertEquals("validations", def.getPluralName());
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a5d0f0c3/ambari-server/src/test/java/org/apache/ambari/server/api/services/RegistryServiceTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/api/services/RegistryServiceTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/RegistryServiceTest.java
new file mode 100644
index 0000000..41bfedf
--- /dev/null
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/RegistryServiceTest.java
@@ -0,0 +1,94 @@
+/**
+ * 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 java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.parsers.RequestBodyParser;
+import org.apache.ambari.server.api.services.registry.RegistryService;
+import org.apache.ambari.server.api.services.serializers.ResultSerializer;
+
+import org.apache.ambari.server.controller.spi.Resource;
+
+/**
+ * Unit tests for RegistryService
+ */
+public class RegistryServiceTest extends BaseServiceTest{
+  @Override
+  public List<BaseServiceTest.ServiceTestInvocation> getTestInvocations() 
throws Exception {
+    List<BaseServiceTest.ServiceTestInvocation> listInvocations = new 
ArrayList<>();
+
+    // getRegistries
+    RegistryService service = new TestRegistryService("null");
+    Method m = service.getClass().getMethod("getRegistries", String.class, 
HttpHeaders.class, UriInfo.class);
+    Object[] args = new Object[]{null, getHttpHeaders(), getUriInfo()};
+    listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, 
m, args, null));
+
+    // getRegistry
+    service = new TestRegistryService("1");
+    m = service.getClass().getMethod("getRegistry", String.class, 
HttpHeaders.class, UriInfo.class, String.class);
+    args = new Object[]{null, getHttpHeaders(), getUriInfo(), ""};
+    listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, 
m, args, null));
+
+    //createRegistry
+    service = new TestRegistryService(null);
+    m = service.getClass().getMethod("createRegistries", String.class, 
HttpHeaders.class, UriInfo.class);
+    args = new Object[]{"body", getHttpHeaders(), getUriInfo()};
+    listInvocations.add(new ServiceTestInvocation(Request.Type.POST, service, 
m, args, "body"));
+
+    return listInvocations;
+  }
+  private class TestRegistryService extends RegistryService {
+
+    private String r_registryId;
+
+    private TestRegistryService(String registryId) {
+      super();
+      r_registryId = registryId;
+    }
+
+    @Override
+    protected ResourceInstance createResource(Resource.Type type, 
Map<Resource.Type, String> mapIds) {
+      return getTestResource();
+    }
+
+
+    RequestFactory getRequestFactory() {
+      return getTestRequestFactory();
+    }
+
+    @Override
+    protected RequestBodyParser getBodyParser() {
+      return getTestBodyParser();
+    }
+
+    @Override
+    protected ResultSerializer getResultSerializer() {
+      return getTestResultSerializer();
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a5d0f0c3/ambari-server/src/test/java/org/apache/ambari/server/controller/RegistryRequestTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/RegistryRequestTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/RegistryRequestTest.java
new file mode 100644
index 0000000..c61cafb
--- /dev/null
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/RegistryRequestTest.java
@@ -0,0 +1,37 @@
+/**
+ * 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.controller;
+
+import org.apache.ambari.server.registry.RegistryType;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Unit tests for RegistryRequest
+ */
+public class RegistryRequestTest {
+  @Test
+  public void testBasicGetAndSet() {
+    RegistryRequest registryRequest =
+            new RegistryRequest((Long) 1L, "hwx", RegistryType.JSON, 
"abc.tar.gz");
+    Assert.assertEquals((Long) 1L, registryRequest.getRegistryId());
+    Assert.assertEquals("abc.tar.gz", registryRequest.getRegistryUri());
+    Assert.assertEquals("hwx", registryRequest.getRegistryName());
+    Assert.assertEquals(RegistryType.JSON, registryRequest.getRegistryType());
+  }
+}

Reply via email to