stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From isu...@apache.org
Subject git commit: tests for parsing Applications
Date Sun, 12 Oct 2014 13:44:49 GMT
Repository: stratos
Updated Branches:
  refs/heads/4.0.0-grouping 8db918085 -> 91a8babd7


tests for parsing Applications


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

Branch: refs/heads/4.0.0-grouping
Commit: 91a8babd73f4c094c976865d337833ff4210ea05
Parents: 8db9180
Author: Isuru Haththotuwa <isuruh@apache.org>
Authored: Sun Oct 12 19:14:25 2014 +0530
Committer: Isuru Haththotuwa <isuruh@apache.org>
Committed: Sun Oct 12 19:14:25 2014 +0530

----------------------------------------------------------------------
 .../application/parser/ParserUtils.java         |  33 ++++-
 .../CompositeApplicationParseTest.java          | 134 ++++++++++++++++++-
 2 files changed, 155 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/91a8babd/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/ParserUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/ParserUtils.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/ParserUtils.java
index 62a98ab..dd72508 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/ParserUtils.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/ParserUtils.java
@@ -19,6 +19,7 @@
 
 package org.apache.stratos.cloud.controller.application.parser;
 
+import org.apache.stratos.cloud.controller.exception.ApplicationDefinitionException;
 import org.apache.stratos.cloud.controller.pojo.application.GroupContext;
 import org.apache.stratos.cloud.controller.pojo.application.SubscribableContext;
 import org.apache.stratos.messaging.domain.topology.StartupOrder;
@@ -27,7 +28,7 @@ import java.util.*;
 
 public class ParserUtils {
 
-    public static Set<StartupOrder> convert (String [] startupOrderArr) {
+    public static Set<StartupOrder> convert (String [] startupOrderArr) throws ApplicationDefinitionException
{
 
         Set<StartupOrder> startupOrders = new HashSet<StartupOrder>();
 
@@ -36,13 +37,30 @@ public class ParserUtils {
         }
 
         for (String commaSeparatedStartupOrder : startupOrderArr) {
-            startupOrders.add(new StartupOrder(Arrays.asList(commaSeparatedStartupOrder.split(","))));
+            startupOrders.add(getStartupOrder(commaSeparatedStartupOrder));
         }
 
         return startupOrders;
     }
 
-    public static Set<StartupOrder> convert (String [] startupOrderArr, GroupContext
groupContext) {
+    private static StartupOrder getStartupOrder (String commaSeparatedStartupOrder) throws
ApplicationDefinitionException{
+
+        List<String> startupOrders = new ArrayList<String>();
+
+        for (String startupOrder : Arrays.asList(commaSeparatedStartupOrder.split(",")))
{
+            startupOrder = startupOrder.trim();
+            if (!startupOrder.startsWith("cartridge.")) {
+                throw new ApplicationDefinitionException("Incorrect Startup Order specified,
should start with 'cartridge.'");
+            }
+
+            startupOrders.add(startupOrder);
+        }
+
+        return new StartupOrder(startupOrders);
+    }
+
+    public static Set<StartupOrder> convert (String [] startupOrderArr, GroupContext
groupContext)
+            throws ApplicationDefinitionException {
 
         Set<StartupOrder> startupOrders = new HashSet<StartupOrder>();
 
@@ -60,7 +78,8 @@ public class ParserUtils {
         return startupOrders;
     }
 
-    private static StartupOrder getStartupOrder (List<String> components, GroupContext
groupContext) {
+    private static StartupOrder getStartupOrder (List<String> components, GroupContext
groupContext)
+            throws ApplicationDefinitionException {
 
         List<String> aliasBasedComponents = new ArrayList<String>();
 
@@ -72,7 +91,7 @@ public class ParserUtils {
                 String cartridgeType = component.substring(10);
                 aliasBasedComponent = getAliasForServiceType(cartridgeType, groupContext);
                 if (aliasBasedComponent == null) {
-                    throw new RuntimeException("Unable convert Startup Order to alias-based;
" +
+                    throw new ApplicationDefinitionException("Unable convert Startup Order
to alias-based; " +
                             "cannot find the matching alias for Service type " + cartridgeType);
                 }
 
@@ -82,14 +101,14 @@ public class ParserUtils {
                 String groupName = component.substring(6);
                 aliasBasedComponent = getAliasForGroupName(groupName, groupContext);
                 if (aliasBasedComponent == null) {
-                    throw new RuntimeException("Unable convert Startup Order to alias-based;
" +
+                    throw new ApplicationDefinitionException("Unable convert Startup Order
to alias-based; " +
                             "cannot find the matching alias for Group name " + groupName);
                 }
 
                 aliasBasedComponent = "group.".concat(aliasBasedComponent);
 
             } else {
-                throw new RuntimeException("Incorrect Startup Order specified");
+                throw new ApplicationDefinitionException("Incorrect Startup Order specified");
             }
             aliasBasedComponents.add(aliasBasedComponent);
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/91a8babd/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/stratos/cloud/controller/application/CompositeApplicationParseTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/stratos/cloud/controller/application/CompositeApplicationParseTest.java
b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/stratos/cloud/controller/application/CompositeApplicationParseTest.java
index c2b76af..a2dc30a 100644
--- a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/stratos/cloud/controller/application/CompositeApplicationParseTest.java
+++ b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/stratos/cloud/controller/application/CompositeApplicationParseTest.java
@@ -25,10 +25,7 @@ import org.apache.stratos.cloud.controller.interfaces.ApplicationParser;
 import org.apache.stratos.cloud.controller.pojo.Cartridge;
 import org.apache.stratos.cloud.controller.pojo.Dependencies;
 import org.apache.stratos.cloud.controller.pojo.ServiceGroup;
-import org.apache.stratos.cloud.controller.pojo.application.ApplicationContext;
-import org.apache.stratos.cloud.controller.pojo.application.ComponentContext;
-import org.apache.stratos.cloud.controller.pojo.application.SubscribableContext;
-import org.apache.stratos.cloud.controller.pojo.application.SubscribableInfoContext;
+import org.apache.stratos.cloud.controller.pojo.application.*;
 import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -104,7 +101,7 @@ public class CompositeApplicationParseTest {
     }
 
     @Test(expected = ApplicationDefinitionException.class)
-    public void testParseSimpleInvalidCartridgeApplication() throws ApplicationDefinitionException
{
+    public void testParseSimpleApplicationWithInvalidCartridge() throws ApplicationDefinitionException
{
 
         ApplicationParser applicationParser = new DefaultApplicationParser();
         ApplicationContext simpleAppCtxt = new ApplicationContext();
@@ -136,6 +133,133 @@ public class CompositeApplicationParseTest {
         applicationParser.parse(simpleAppCtxt);
     }
 
+    @Test(expected = ApplicationDefinitionException.class)
+    public void testParseSimpleApplicationWithoutSubcriptionInformation() throws ApplicationDefinitionException
{
+
+        ApplicationParser applicationParser = new DefaultApplicationParser();
+        ApplicationContext simpleAppCtxt = new ApplicationContext();
+        // app id
+        simpleAppCtxt.setApplicationId("simpleInvalidApp");
+        simpleAppCtxt.setAlias("simpleInvalidAppAlias");
+        // tenant info
+        simpleAppCtxt.setTenantId(-1234);
+        // components
+        ComponentContext simpleAppComponentCtxt = new ComponentContext();
+        SubscribableContext simpleAppSubscribableContext = new SubscribableContext();
+        // give invalid cartridge type
+        simpleAppSubscribableContext.setType("php1");
+        simpleAppSubscribableContext.setAlias("myphp");
+        simpleAppComponentCtxt.setSubscribableContexts(new SubscribableContext[]{simpleAppSubscribableContext});
+        simpleAppCtxt.setComponents(simpleAppComponentCtxt);
+        // invalid Subscription information
+        SubscribableInfoContext simpleAppEmptySubscribableInfoCtxt = new SubscribableInfoContext();
+        simpleAppCtxt.setSubscribableInfoContext(new SubscribableInfoContext[]{simpleAppEmptySubscribableInfoCtxt});
+
+        // parse
+        applicationParser.parse(simpleAppCtxt);
+    }
+
+    @Test
+    public void testParseSimpleApplicationWithMultipleSubsriptions () throws ApplicationDefinitionException
{
+
+        ApplicationParser applicationParser = new DefaultApplicationParser();
+        ApplicationContext simpleAppCtxt = new ApplicationContext();
+        // app id
+        simpleAppCtxt.setApplicationId("simpleInvalidApp");
+        simpleAppCtxt.setAlias("simpleInvalidAppAlias");
+        // tenant info
+        simpleAppCtxt.setTenantId(-1234);
+        // components
+        ComponentContext simpleAppComponentCtxt = new ComponentContext();
+        SubscribableContext simpleAppPhpSubscribableContext = new SubscribableContext();
+        simpleAppPhpSubscribableContext.setType("php");
+        simpleAppPhpSubscribableContext.setAlias("myphp");
+        SubscribableContext simpleAppMySqlSubscribableContext = new SubscribableContext();
+        simpleAppMySqlSubscribableContext.setType("mysql");
+        simpleAppMySqlSubscribableContext.setAlias("mysql1");
+        simpleAppComponentCtxt.setSubscribableContexts(new SubscribableContext[]{simpleAppPhpSubscribableContext,
+                simpleAppMySqlSubscribableContext});
+
+        DependencyContext simpleAppDependecyCtxt = new DependencyContext();
+        simpleAppDependecyCtxt.setKillBehaviour("kill-dependents");
+        simpleAppDependecyCtxt.setStartupOrdersContexts(new String[]{"cartridge.mysql1,cartridge.myphp"});
+        simpleAppComponentCtxt.setDependencyContext(simpleAppDependecyCtxt);
+
+        simpleAppCtxt.setComponents(simpleAppComponentCtxt);
+
+        // subscribable information
+        SubscribableInfoContext simpleAppPhpSubscribableInfoCtxt = new SubscribableInfoContext();
+        simpleAppPhpSubscribableInfoCtxt.setAlias("myphp");
+        simpleAppPhpSubscribableInfoCtxt.setAutoscalingPolicy("deployment_policy_1");
+        simpleAppPhpSubscribableInfoCtxt.setAutoscalingPolicy("autoscale_policy_1");
+        simpleAppPhpSubscribableInfoCtxt.setRepoUrl("www.mygit.com/myphp.git");
+        simpleAppPhpSubscribableInfoCtxt.setPrivateRepo(true);
+        simpleAppPhpSubscribableInfoCtxt.setRepoUsername("admin");
+        simpleAppPhpSubscribableInfoCtxt.setRepoUrl("admin123");
+
+        SubscribableInfoContext simpleAppMySqlSubscribableInfoCtxt = new SubscribableInfoContext();
+        simpleAppMySqlSubscribableInfoCtxt.setAlias("mysql1");
+        simpleAppMySqlSubscribableInfoCtxt.setAutoscalingPolicy("deployment_policy_2");
+        simpleAppMySqlSubscribableInfoCtxt.setAutoscalingPolicy("autoscale_policy_2");
+
+        simpleAppCtxt.setSubscribableInfoContext(new SubscribableInfoContext[]{simpleAppPhpSubscribableInfoCtxt,
+                simpleAppMySqlSubscribableInfoCtxt});
+
+        // parse
+        applicationParser.parse(simpleAppCtxt);
+    }
+
+    @Test(expected = ApplicationDefinitionException.class)
+    public void testParseSimpleApplicationWithMultipleSubsriptionsInvalidStartupOrder ()
throws ApplicationDefinitionException {
+
+        ApplicationParser applicationParser = new DefaultApplicationParser();
+        ApplicationContext simpleAppCtxt = new ApplicationContext();
+        // app id
+        simpleAppCtxt.setApplicationId("simpleInvalidApp");
+        simpleAppCtxt.setAlias("simpleInvalidAppAlias");
+        // tenant info
+        simpleAppCtxt.setTenantId(-1234);
+        // components
+        ComponentContext simpleAppComponentCtxt = new ComponentContext();
+        SubscribableContext simpleAppPhpSubscribableContext = new SubscribableContext();
+        simpleAppPhpSubscribableContext.setType("php");
+        simpleAppPhpSubscribableContext.setAlias("myphp");
+        SubscribableContext simpleAppMySqlSubscribableContext = new SubscribableContext();
+        simpleAppMySqlSubscribableContext.setType("mysql");
+        simpleAppMySqlSubscribableContext.setAlias("mysql1");
+        simpleAppComponentCtxt.setSubscribableContexts(new SubscribableContext[]{simpleAppPhpSubscribableContext,
+                simpleAppMySqlSubscribableContext});
+
+        DependencyContext simpleAppDependecyCtxt = new DependencyContext();
+        simpleAppDependecyCtxt.setKillBehaviour("kill-dependents");
+        // startup order is invalid, without prefix 'cartridge.' for mysql1
+        simpleAppDependecyCtxt.setStartupOrdersContexts(new String[]{"mysql1,cartridge.myphp"});
+        simpleAppComponentCtxt.setDependencyContext(simpleAppDependecyCtxt);
+
+        simpleAppCtxt.setComponents(simpleAppComponentCtxt);
+
+        // subscribable information
+        SubscribableInfoContext simpleAppPhpSubscribableInfoCtxt = new SubscribableInfoContext();
+        simpleAppPhpSubscribableInfoCtxt.setAlias("myphp");
+        simpleAppPhpSubscribableInfoCtxt.setAutoscalingPolicy("deployment_policy_1");
+        simpleAppPhpSubscribableInfoCtxt.setAutoscalingPolicy("autoscale_policy_1");
+        simpleAppPhpSubscribableInfoCtxt.setRepoUrl("www.mygit.com/myphp.git");
+        simpleAppPhpSubscribableInfoCtxt.setPrivateRepo(true);
+        simpleAppPhpSubscribableInfoCtxt.setRepoUsername("admin");
+        simpleAppPhpSubscribableInfoCtxt.setRepoUrl("admin123");
+
+        SubscribableInfoContext simpleAppMySqlSubscribableInfoCtxt = new SubscribableInfoContext();
+        simpleAppMySqlSubscribableInfoCtxt.setAlias("mysql1");
+        simpleAppMySqlSubscribableInfoCtxt.setAutoscalingPolicy("deployment_policy_2");
+        simpleAppMySqlSubscribableInfoCtxt.setAutoscalingPolicy("autoscale_policy_2");
+
+        simpleAppCtxt.setSubscribableInfoContext(new SubscribableInfoContext[]{simpleAppPhpSubscribableInfoCtxt,
+                simpleAppMySqlSubscribableInfoCtxt});
+
+        // parse
+        applicationParser.parse(simpleAppCtxt);
+    }
+
     @AfterClass
     public static void tearDownAfterClass() {
 


Mime
View raw message