From commits-return-51126-archive-asf-public=cust-asf.ponee.io@ambari.apache.org Mon Jan 15 15:10:32 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id E1BBF180657 for ; Mon, 15 Jan 2018 15:10:32 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D1F90160C31; Mon, 15 Jan 2018 14:10:32 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F04E7160C25 for ; Mon, 15 Jan 2018 15:10:31 +0100 (CET) Received: (qmail 2863 invoked by uid 500); 15 Jan 2018 14:10:31 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 2854 invoked by uid 99); 15 Jan 2018 14:10:31 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jan 2018 14:10:31 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id AB53581C0B; Mon, 15 Jan 2018 14:10:29 +0000 (UTC) Date: Mon, 15 Jan 2018 14:10:29 +0000 To: "commits@ambari.apache.org" Subject: [ambari] branch trunk updated: AMBARI-22771. Fix broken unit test MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <151602542963.5357.15499444335308557183@gitbox.apache.org> From: adoroszlai@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: ambari X-Git-Refname: refs/heads/trunk X-Git-Reftype: branch X-Git-Oldrev: 008a3c1ef08b7fa39668b3e563cb88d5b414bec9 X-Git-Newrev: 0e321500a17d454e978e1e59c74453e02a22d3a3 X-Git-Rev: 0e321500a17d454e978e1e59c74453e02a22d3a3 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. adoroszlai pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ambari.git The following commit(s) were added to refs/heads/trunk by this push: new 0e32150 AMBARI-22771. Fix broken unit test 0e32150 is described below commit 0e321500a17d454e978e1e59c74453e02a22d3a3 Author: Doroszlai, Attila AuthorDate: Mon Jan 15 15:00:11 2018 +0100 AMBARI-22771. Fix broken unit test --- .../controller/RootServiceResponseFactoryTest.java | 145 ++++++++++----------- 1 file changed, 69 insertions(+), 76 deletions(-) diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java index e194115..2e16766 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java @@ -20,6 +20,8 @@ package org.apache.ambari.server.controller; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; +import static org.apache.ambari.server.controller.RootComponent.AMBARI_SERVER; +import static org.apache.ambari.server.controller.RootService.AMBARI; import java.sql.SQLException; import java.util.Collections; @@ -29,6 +31,7 @@ import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.H2DatabaseCleaner; import org.apache.ambari.server.ObjectNotFoundException; import org.apache.ambari.server.api.services.AmbariMetaInfo; +import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.orm.GuiceJpaInitializer; import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.junit.After; @@ -41,13 +44,17 @@ import com.google.inject.Injector; public class RootServiceResponseFactoryTest { + private Injector injector; + @Inject private RootServiceResponseFactory responseFactory; - private Injector injector; @Inject private AmbariMetaInfo ambariMetaInfo; + @Inject + private Configuration config; + @Before public void setUp() throws Exception { injector = Guice.createInjector(new InMemoryDefaultTestModule()); @@ -61,116 +68,102 @@ public class RootServiceResponseFactoryTest { } @Test - public void testGetRootServices() throws Exception { + public void getReturnsAllServicesForNullServiceName() throws Exception { // Request a null service name RootServiceRequest request = new RootServiceRequest(null); Set rootServices = responseFactory.getRootServices(request); - assertEquals(RootService.values().length, - rootServices.size()); + assertEquals(RootService.values().length, rootServices.size()); + } + @Test + public void getReturnsAllServicesForNullRequest() throws Exception { // null request - request = null; - rootServices = responseFactory.getRootServices(request); - assertEquals(RootService.values().length, - rootServices.size()); + Set rootServices = responseFactory.getRootServices(null); + assertEquals(RootService.values().length, rootServices.size()); + } + @Test(expected = ObjectNotFoundException.class) + public void getThrowsForNonExistentService() throws Exception { // Request nonexistent service - try { - request = new RootServiceRequest("XXX"); - rootServices = responseFactory.getRootServices(request); - } catch (Exception e) { - assertTrue(e instanceof ObjectNotFoundException); - } + RootServiceRequest request = new RootServiceRequest("XXX"); + responseFactory.getRootServices(request); + } + @Test + public void getReturnsSingleServiceForValidServiceName() throws Exception { // Request existent service - request = new RootServiceRequest( - RootService.AMBARI.name()); - - rootServices = responseFactory.getRootServices(request); - assertEquals(1, rootServices.size()); - assertTrue(rootServices.contains(new RootServiceResponse( - RootService.AMBARI.name()))); + RootServiceRequest request = new RootServiceRequest(AMBARI.name()); + Set rootServices = responseFactory.getRootServices(request); + assertEquals(Collections.singleton(new RootServiceResponse(AMBARI.name())), rootServices); } - @Test - public void testGetRootServiceComponents() throws Exception { + @Test(expected = ObjectNotFoundException.class) + public void getThrowsForNullServiceNameNullComponentName() throws Exception { // Request null service name, null component name - RootServiceComponentRequest request = new RootServiceComponentRequest(null, - null); - - Set rootServiceComponents; - try { - rootServiceComponents = responseFactory.getRootServiceComponents(request); - } catch (Exception e) { - assertTrue(e instanceof ObjectNotFoundException); - } + RootServiceComponentRequest request = new RootServiceComponentRequest(null, null); - RootComponent ambariServerComponent = RootComponent.AMBARI_SERVER; + responseFactory.getRootServiceComponents(request); + } + @Test(expected = ObjectNotFoundException.class) + public void getThrowsForNullServiceNameValidComponentName() throws Exception { // Request null service name, not-null component name - request = new RootServiceComponentRequest(null, ambariServerComponent.name()); + RootServiceComponentRequest request = new RootServiceComponentRequest(null, AMBARI_SERVER.name()); - try { - rootServiceComponents = responseFactory.getRootServiceComponents(request); - } catch (Exception e) { - assertTrue(e instanceof ObjectNotFoundException); - } + responseFactory.getRootServiceComponents(request); + } + @Test + public void getReturnsAllComponentsForValidServiceNameNullComponentName() throws Exception { // Request existent service name, null component name - String serviceName = RootService.AMBARI.name(); - request = new RootServiceComponentRequest(serviceName, null); - - rootServiceComponents = responseFactory.getRootServiceComponents(request); - assertEquals( - RootService.AMBARI.getComponents().length, - rootServiceComponents.size()); + RootServiceComponentRequest request = new RootServiceComponentRequest(AMBARI.name(), null); - String ambariVersion = ambariMetaInfo.getServerVersion(); + Set rootServiceComponents = responseFactory.getRootServiceComponents(request); + assertEquals(AMBARI.getComponents().length, rootServiceComponents.size()); - for (int i = 0; i < RootService.AMBARI.getComponents().length; i++) { - RootComponent component = RootService.AMBARI.getComponents()[i]; + for (int i = 0; i < AMBARI.getComponents().length; i++) { + RootComponent component = AMBARI.getComponents()[i]; - if (component.name().equals(ambariServerComponent.name())) { + if (component.name().equals(AMBARI_SERVER.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")); + if (response.getComponentName().equals(AMBARI_SERVER.name())) { + verifyResponseForAmbariServer(response); } } } else { assertTrue(rootServiceComponents.contains(new RootServiceComponentResponse( - serviceName, component.name(), RootServiceResponseFactory.NOT_APPLICABLE, + AMBARI.name(), component.name(), RootServiceResponseFactory.NOT_APPLICABLE, Collections.emptyMap()))); } } + } + @Test + public void getReturnsSingleComponentForValidServiceAndComponentName() throws Exception { // Request existent service name, existent component name - request = new RootServiceComponentRequest( - RootService.AMBARI.name(), - RootService.AMBARI.getComponents()[0].name()); + RootServiceComponentRequest request = new RootServiceComponentRequest(AMBARI.name(), AMBARI_SERVER.name()); + + Set rootServiceComponents = responseFactory.getRootServiceComponents(request); - rootServiceComponents = responseFactory.getRootServiceComponents(request); assertEquals(1, rootServiceComponents.size()); for (RootServiceComponentResponse response : rootServiceComponents) { - if (response.getComponentName().equals( - RootService.AMBARI.getComponents()[0].name())) { - assertEquals(ambariVersion, response.getComponentVersion()); - assertEquals(2, response.getProperties().size()); - assertTrue(response.getProperties().containsKey("jdk_location")); - assertTrue(response.getProperties().containsKey("java.version")); - } + verifyResponseForAmbariServer(response); } + } - // Request existent service name, and component, not belongs to requested - // service - request = new RootServiceComponentRequest( - RootService.AMBARI.name(), "XXX"); - - try { - rootServiceComponents = responseFactory.getRootServiceComponents(request); - } catch (Exception e) { - assertTrue(e instanceof ObjectNotFoundException); - } + @Test(expected = ObjectNotFoundException.class) + public void getThrowsForNonexistentComponent() throws Exception { + // Request existent service name, and component, not belongs to requested service + RootServiceComponentRequest request = new RootServiceComponentRequest(AMBARI.name(), "XXX"); + responseFactory.getRootServiceComponents(request); + } + + private void verifyResponseForAmbariServer(RootServiceComponentResponse response) { + assertEquals(ambariMetaInfo.getServerVersion(), response.getComponentVersion()); + // all properties from config + "jdk_location" + "java.version" + int expectedPropertyCount = config.getAmbariProperties().size() + 2; + assertEquals(response.getProperties().toString(), expectedPropertyCount, response.getProperties().size()); + assertTrue(response.getProperties().containsKey("jdk_location")); + assertTrue(response.getProperties().containsKey("java.version")); } } -- To stop receiving notification emails like this one, please contact ['"commits@ambari.apache.org" '].