Adding the unit test to the aws lb extension
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/44f52701 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/44f52701 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/44f52701 Branch: refs/heads/stratos-4.1.x Commit: 44f527018cb13fcaf2acdf19f397b69fb9561267 Parents: 824f024 Author: gayangunarathne <[email protected]> Authored: Mon Nov 16 19:06:07 2015 +0530 Committer: gayangunarathne <[email protected]> Committed: Mon Nov 16 20:07:37 2015 +0530 ---------------------------------------------------------------------- .../stratos/aws/extension/AwsHelperTest.java | 82 ++++++++++++++++++++ .../src/test/resources/log4j.properties | 28 +++++++ 2 files changed, 110 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/44f52701/extensions/load-balancer/modules/aws-extension/src/test/java/org/apache/stratos/aws/extension/AwsHelperTest.java ---------------------------------------------------------------------- diff --git a/extensions/load-balancer/modules/aws-extension/src/test/java/org/apache/stratos/aws/extension/AwsHelperTest.java b/extensions/load-balancer/modules/aws-extension/src/test/java/org/apache/stratos/aws/extension/AwsHelperTest.java new file mode 100644 index 0000000..840227d --- /dev/null +++ b/extensions/load-balancer/modules/aws-extension/src/test/java/org/apache/stratos/aws/extension/AwsHelperTest.java @@ -0,0 +1,82 @@ +/* + * 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.aws.extension; + +import com.amazonaws.services.ec2.model.Filter; +import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; + +import org.junit.*; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Set; + + +/** + * AwsHelper util test. + */ +public class AwsHelperTest { + + @Test + public void testSecurityGroupFilters() + throws LoadBalancerExtensionException, NoSuchMethodException, InvocationTargetException, + IllegalAccessException { + Set<Filter> filters=(Set<Filter>)genericInvokMethod(new AWSHelper(null,null), "getFilters",2,"Test VPC ID","test"); + + Assert.assertNotNull(filters); + Assert.assertEquals(2,filters.size()); + + } + + /** + * Method to access the private methods + * @param obj + * @param methodName + * @param paramCount + * @param params + * @return + */ + public static Object genericInvokMethod(Object obj, String methodName, + int paramCount, Object... params) { + Method method; + Object requiredObj = null; + Object[] parameters = new Object[paramCount]; + Class<?>[] classArray = new Class<?>[paramCount]; + for (int i = 0; i < paramCount; i++) { + parameters[i] = params[i]; + classArray[i] = params[i].getClass(); + } + try { + method = obj.getClass().getDeclaredMethod(methodName, classArray); + method.setAccessible(true); + requiredObj = method.invoke(obj, params); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + + return requiredObj; + } + } http://git-wip-us.apache.org/repos/asf/stratos/blob/44f52701/extensions/load-balancer/modules/aws-extension/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/extensions/load-balancer/modules/aws-extension/src/test/resources/log4j.properties b/extensions/load-balancer/modules/aws-extension/src/test/resources/log4j.properties new file mode 100644 index 0000000..1da5b96 --- /dev/null +++ b/extensions/load-balancer/modules/aws-extension/src/test/resources/log4j.properties @@ -0,0 +1,28 @@ +# +# +# 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. +# +# + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.Target=System.out +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1} [%t] %n%m%n + +#Loggers +log4j.rootLogger=info, console
