|
| 1 | +// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Universal Permissive License v 1.0 as shown at |
| 3 | +// http://oss.oracle.com/licenses/upl. |
| 4 | + |
| 5 | +package oracle.kubernetes.operator; |
| 6 | + |
| 7 | +import static org.junit.Assert.assertFalse; |
| 8 | +import static org.junit.Assert.assertTrue; |
| 9 | + |
| 10 | +import java.lang.reflect.InvocationTargetException; |
| 11 | +import java.lang.reflect.Method; |
| 12 | +import java.util.Collection; |
| 13 | +import org.junit.Test; |
| 14 | + |
| 15 | +public class MainTest { |
| 16 | + |
| 17 | + @Test |
| 18 | + public void getTargetNamespaces_withEmptyValue_should_return_default() |
| 19 | + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
| 20 | + Collection<String> namespaces = invoke_getTargetNamespaces("", "default"); |
| 21 | + assertTrue(namespaces.contains("default")); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + public void getTargetNamespaces_withNonEmptyValue_should_not_return_default() |
| 26 | + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
| 27 | + Collection<String> namespaces = invoke_getTargetNamespaces("dev-domain", "default"); |
| 28 | + assertFalse(namespaces.contains("default")); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void getTargetNamespaces_with_single_target_should_return_it() |
| 33 | + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
| 34 | + Collection<String> namespaces = invoke_getTargetNamespaces("dev-domain", "default"); |
| 35 | + assertTrue(namespaces.contains("dev-domain")); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void getTargetNamespaces_with_multiple_targets_should_include_all() |
| 40 | + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
| 41 | + Collection<String> namespaces = |
| 42 | + invoke_getTargetNamespaces("dev-domain,domain1,test-domain", "default"); |
| 43 | + assertTrue(namespaces.contains("dev-domain")); |
| 44 | + assertTrue(namespaces.contains("domain1")); |
| 45 | + assertTrue(namespaces.contains("test-domain")); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void getTargetNamespaces_should_remove_leading_spaces() |
| 50 | + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
| 51 | + Collection<String> namespaces = |
| 52 | + invoke_getTargetNamespaces(" test-domain, dev-domain", "default"); |
| 53 | + assertTrue(namespaces.contains("dev-domain")); |
| 54 | + assertTrue(namespaces.contains("test-domain")); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void getTargetNamespaces_should_remove_trailing_spaces() |
| 59 | + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
| 60 | + Collection<String> namespaces = |
| 61 | + invoke_getTargetNamespaces("dev-domain ,test-domain ", "default"); |
| 62 | + assertTrue(namespaces.contains("dev-domain")); |
| 63 | + assertTrue(namespaces.contains("test-domain")); |
| 64 | + } |
| 65 | + |
| 66 | + Method getTargetNamespaces; |
| 67 | + |
| 68 | + Collection<String> invoke_getTargetNamespaces(String tnValue, String namespace) |
| 69 | + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
| 70 | + if (getTargetNamespaces == null) { |
| 71 | + getTargetNamespaces = |
| 72 | + Main.class.getDeclaredMethod("getTargetNamespaces", String.class, String.class); |
| 73 | + getTargetNamespaces.setAccessible(true); |
| 74 | + } |
| 75 | + return (Collection<String>) getTargetNamespaces.invoke(null, tnValue, namespace); |
| 76 | + } |
| 77 | +} |
0 commit comments