You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/10/01 06:06:04 UTC

[3/3] git commit: Initial version of CC unit tests using Mockito - testDeployCartridgeDefinition#exceptions

Initial version of CC unit tests using Mockito - testDeployCartridgeDefinition#exceptions


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

Branch: refs/heads/cc-unit-tests
Commit: 46d085e30db89aae3dd8a218298b34c7e8145697
Parents: 517f35c
Author: Nirmal Fernando <ni...@gmail.com>
Authored: Wed Oct 1 09:03:42 2014 +0530
Committer: Nirmal Fernando <ni...@gmail.com>
Committed: Wed Oct 1 09:03:42 2014 +0530

----------------------------------------------------------------------
 .../impl/CloudControllerServiceImplTest.java    | 72 ++++++++++++++++++++
 1 file changed, 72 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/46d085e3/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImplTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImplTest.java b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImplTest.java
new file mode 100644
index 0000000..36c82c9
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImplTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.stratos.cloud.controller.impl;
+
+import org.apache.stratos.cloud.controller.exception.InvalidCartridgeDefinitionException;
+import org.apache.stratos.cloud.controller.pojo.CartridgeConfig;
+import org.apache.stratos.cloud.controller.registry.RegistryManager;
+import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
+import org.apache.stratos.cloud.controller.util.ServiceReferenceHolder;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.wso2.carbon.registry.core.session.UserRegistry;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+/**
+ * Testing operations provided by Cloud Controller.
+ */
+public class CloudControllerServiceImplTest {
+	private static RegistryManager registry;
+	private static FasterLookUpDataHolder data ;
+	private static ServiceReferenceHolder serviceRefHolder =
+			ServiceReferenceHolder.getInstance();
+	private static CloudControllerServiceImpl service;
+
+	@BeforeClass
+	public static void setUp(){
+		UserRegistry userReg = mock(UserRegistry.class);
+		serviceRefHolder = mock(ServiceReferenceHolder.class);
+		
+		when(serviceRefHolder.getRegistry()).thenReturn(userReg);
+		
+		registry = mock(RegistryManager.class);
+		when(registry.retrieve()).thenReturn(null);
+		
+		data = mock(FasterLookUpDataHolder.class);
+		
+		service = new CloudControllerServiceImpl(true);
+		
+	}
+	
+	@Test
+	public void testDeployCartridgeDefinition() throws Exception {
+		CartridgeConfig cartridgeConfig = new CartridgeConfig();
+		cartridgeConfig.setType("php");
+		cartridgeConfig.setBaseDir("/tmp");
+		try {
+			service.deployCartridgeDefinition(cartridgeConfig);
+		} catch(Exception e) {
+			assertEquals(InvalidCartridgeDefinitionException.class, e.getClass());
+			assertEquals("Invalid Cartridge Definition: Cartridge Type: php. "
+					+ "Cause: Iaases of this Cartridge is null or empty.", e.getMessage());
+		}
+	}
+}