Repository: ambari Updated Branches: refs/heads/trunk 9a85b8b7c -> 8cc5cabcb
AMBARI-6318 - Views : Admin - Add Permission Resource (fix test name) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8cc5cabc Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8cc5cabc Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8cc5cabc Branch: refs/heads/trunk Commit: 8cc5cabcb3cb7a34b5fa4a0ff016f8dd82268d89 Parents: 9a85b8b Author: tbeerbower <[email protected]> Authored: Wed Jul 2 12:13:39 2014 -0400 Committer: tbeerbower <[email protected]> Committed: Wed Jul 2 12:13:39 2014 -0400 ---------------------------------------------------------------------- .../api/services/PermissionServiceTest.java | 105 ++++++++++++++++++ .../api/services/permissionServiceTest.java | 106 ------------------- 2 files changed, 105 insertions(+), 106 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/8cc5cabc/ambari-server/src/test/java/org/apache/ambari/server/api/services/PermissionServiceTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/PermissionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/PermissionServiceTest.java new file mode 100644 index 0000000..620643f --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/PermissionServiceTest.java @@ -0,0 +1,105 @@ +/** + * 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.resources.ResourceInstance; +import org.apache.ambari.server.api.services.parsers.RequestBodyParser; +import org.apache.ambari.server.api.services.serializers.ResultSerializer; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.UriInfo; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + + +/** + * Unit tests for PermissionService. + */ +public class PermissionServiceTest extends BaseServiceTest { + + public List<ServiceTestInvocation> getTestInvocations() throws Exception { + List<ServiceTestInvocation> listInvocations = new ArrayList<ServiceTestInvocation>(); + + //getPermission + PermissionService service = new TestPermissionService("id"); + Method m = service.getClass().getMethod("getPermission", HttpHeaders.class, UriInfo.class, String.class); + Object[] args = new Object[] {getHttpHeaders(), getUriInfo(), "id"}; + listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, m, args, null)); + + //getPermissions + service = new TestPermissionService(null); + m = service.getClass().getMethod("getPermissions", HttpHeaders.class, UriInfo.class); + args = new Object[] {getHttpHeaders(), getUriInfo()}; + listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, m, args, null)); + + //createPermission + service = new TestPermissionService("id"); + m = service.getClass().getMethod("createPermission", String.class, HttpHeaders.class, UriInfo.class, String.class); + args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "id"}; + listInvocations.add(new ServiceTestInvocation(Request.Type.POST, service, m, args, "body")); + + //createPermission + service = new TestPermissionService("id"); + m = service.getClass().getMethod("updatePermission", String.class, HttpHeaders.class, UriInfo.class, String.class); + args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "id"}; + listInvocations.add(new ServiceTestInvocation(Request.Type.PUT, service, m, args, "body")); + + //deletePermission + service = new TestPermissionService("id"); + m = service.getClass().getMethod("deletePermission", HttpHeaders.class, UriInfo.class, String.class); + args = new Object[] {getHttpHeaders(), getUriInfo(), "id"}; + listInvocations.add(new ServiceTestInvocation(Request.Type.DELETE, service, m, args, null)); + + return listInvocations; + } + + + private class TestPermissionService extends PermissionService { + private String id; + + private TestPermissionService(String id) { + this.id = id; + } + + @Override + protected ResourceInstance createPermissionResource(String id) { + assertEquals(this.id, id); + return getTestResource(); + } + + @Override + 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/8cc5cabc/ambari-server/src/test/java/org/apache/ambari/server/api/services/permissionServiceTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/permissionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/permissionServiceTest.java deleted file mode 100644 index 1d3efac..0000000 --- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/permissionServiceTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * 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.resources.ResourceInstance; -import org.apache.ambari.server.api.services.parsers.RequestBodyParser; -import org.apache.ambari.server.api.services.serializers.ResultSerializer; - -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.UriInfo; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; - - -/** - * Unit tests for PermissionService. - */ -public class PermissionServiceTest extends BaseServiceTest { - - - public List<ServiceTestInvocation> getTestInvocations() throws Exception { - List<ServiceTestInvocation> listInvocations = new ArrayList<ServiceTestInvocation>(); - - //getPermission - PermissionService service = new TestPermissionService("id"); - Method m = service.getClass().getMethod("getPermission", HttpHeaders.class, UriInfo.class, String.class); - Object[] args = new Object[] {getHttpHeaders(), getUriInfo(), "id"}; - listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, m, args, null)); - - //getPermissions - service = new TestPermissionService(null); - m = service.getClass().getMethod("getPermissions", HttpHeaders.class, UriInfo.class); - args = new Object[] {getHttpHeaders(), getUriInfo()}; - listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, m, args, null)); - - //createPermission - service = new TestPermissionService("id"); - m = service.getClass().getMethod("createPermission", String.class, HttpHeaders.class, UriInfo.class, String.class); - args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "id"}; - listInvocations.add(new ServiceTestInvocation(Request.Type.POST, service, m, args, "body")); - - //createPermission - service = new TestPermissionService("id"); - m = service.getClass().getMethod("updatePermission", String.class, HttpHeaders.class, UriInfo.class, String.class); - args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "id"}; - listInvocations.add(new ServiceTestInvocation(Request.Type.PUT, service, m, args, "body")); - - //deletePermission - service = new TestPermissionService("id"); - m = service.getClass().getMethod("deletePermission", HttpHeaders.class, UriInfo.class, String.class); - args = new Object[] {getHttpHeaders(), getUriInfo(), "id"}; - listInvocations.add(new ServiceTestInvocation(Request.Type.DELETE, service, m, args, null)); - - return listInvocations; - } - - - private class TestPermissionService extends PermissionService { - private String id; - - private TestPermissionService(String id) { - this.id = id; - } - - @Override - protected ResourceInstance createPermissionResource(String id) { - assertEquals(this.id, id); - return getTestResource(); - } - - @Override - RequestFactory getRequestFactory() { - return getTestRequestFactory(); - } - - @Override - protected RequestBodyParser getBodyParser() { - return getTestBodyParser(); - } - - @Override - protected ResultSerializer getResultSerializer() { - return getTestResultSerializer(); - } - } -}
