|
| 1 | +package com.nexttimespace.cdnservice; |
| 2 | + |
| 3 | +import java.util.Properties; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Assertions; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +public class MainApplicationTest { |
| 9 | + |
| 10 | + @Test |
| 11 | + public void validateConfigurationTest() { |
| 12 | + Properties properties = null; |
| 13 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 14 | + |
| 15 | + properties = TestUtils.getClonedPropety(); |
| 16 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 17 | + } |
| 18 | + |
| 19 | + @Test |
| 20 | + public void validateConfigurationTestServerConfigNegativeCase() { |
| 21 | + Properties properties = TestUtils.getClonedPropety(); |
| 22 | + properties.setProperty("server.http.port", "abc"); |
| 23 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 24 | + |
| 25 | + properties = TestUtils.getClonedPropety(); |
| 26 | + properties.setProperty("server.ssl-config.port", "abc"); |
| 27 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 28 | + |
| 29 | + properties = TestUtils.getClonedPropety(); |
| 30 | + properties.setProperty("server.ssl-config.key-store", "abc"); |
| 31 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 32 | + |
| 33 | + properties = TestUtils.getClonedPropety(); |
| 34 | + properties.setProperty("server.ssl-config.trust-store", "abc"); |
| 35 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 36 | + |
| 37 | + properties = TestUtils.getClonedPropety(); |
| 38 | + properties.setProperty("server.ssl-config.key-store-password", ""); |
| 39 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 40 | + |
| 41 | + properties = TestUtils.getClonedPropety(); |
| 42 | + properties.setProperty("server.ssl-config.trust-store-password", ""); |
| 43 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void validateConfigurationTestRepoConfig() { |
| 48 | + Properties properties = TestUtils.getClonedPropety(); |
| 49 | + properties.setProperty("repo[0].type", "abc"); |
| 50 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 51 | + |
| 52 | + properties = TestUtils.getClonedPropety(); |
| 53 | + properties.setProperty("repo[0].alias", ""); |
| 54 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 55 | + |
| 56 | + properties = TestUtils.getClonedPropety(); |
| 57 | + properties.setProperty("repo[0].allow-publish", ""); |
| 58 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 59 | + |
| 60 | + properties = TestUtils.getClonedPropety(); |
| 61 | + properties.setProperty("repo[0].allow-publish", "true"); |
| 62 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 63 | + |
| 64 | + properties = TestUtils.getClonedPropety(); |
| 65 | + properties.setProperty("repo[0].allow-publish", "false"); |
| 66 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 67 | + |
| 68 | + properties = TestUtils.getClonedPropety(); |
| 69 | + properties.setProperty("repo[0].traffic", "abc"); |
| 70 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 71 | + |
| 72 | + properties = TestUtils.getClonedPropety(); |
| 73 | + properties.setProperty("repo[0].traffic", "80"); |
| 74 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 75 | + |
| 76 | + properties = TestUtils.getClonedPropety(); |
| 77 | + properties.setProperty("repo[0].directory.path", "abc"); |
| 78 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 79 | + |
| 80 | + properties = TestUtils.getClonedPropety(); |
| 81 | + properties.setProperty("repo[0].response.header", "abc"); |
| 82 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 83 | + |
| 84 | + properties = TestUtils.getClonedPropety(); |
| 85 | + properties.setProperty("repo[0].response.header", ""); |
| 86 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 87 | + |
| 88 | + properties = TestUtils.getClonedPropety(); |
| 89 | + properties.setProperty("repo[0].response.header", "|"); |
| 90 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 91 | + |
| 92 | + properties = TestUtils.getClonedPropety(); |
| 93 | + properties.setProperty("repo[0].response.header", "abc|cdb"); |
| 94 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 95 | + |
| 96 | + properties = TestUtils.getClonedPropety(); |
| 97 | + properties.setProperty("repo[0].response.header", "abc:|cdb:"); |
| 98 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 99 | + |
| 100 | + properties = TestUtils.getClonedPropety(); |
| 101 | + properties.remove("repo[0].response.header"); |
| 102 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 103 | + |
| 104 | + properties = TestUtils.getClonedPropety(); |
| 105 | + properties.setProperty("repo[0].cache-manager.enable", "false"); |
| 106 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 107 | + |
| 108 | + properties = TestUtils.getClonedPropety(); |
| 109 | + properties.setProperty("repo[0].cache-manager.enable", "abc"); |
| 110 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 111 | + |
| 112 | + properties = TestUtils.getClonedPropety(); |
| 113 | + properties.remove("repo[0].cache-manager.enable"); |
| 114 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 115 | + |
| 116 | + properties = TestUtils.getClonedPropety(); |
| 117 | + properties.setProperty("repo[0].cache-manager.type", "abc"); |
| 118 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 119 | + |
| 120 | + |
| 121 | + properties = TestUtils.getClonedPropety(); |
| 122 | + properties.setProperty("repo[0].cache-manager.clear-strategy.type", "abc"); |
| 123 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 124 | + |
| 125 | + properties = TestUtils.getClonedPropety(); |
| 126 | + properties.remove("repo[0].cache-manager.clear-strategy.type"); |
| 127 | + Assertions.assertTrue(MainApplication.validateConfiguration(properties)); |
| 128 | + |
| 129 | + properties = TestUtils.getClonedPropety(); |
| 130 | + properties.setProperty("repo[0].cache-manager.clear-strategy.tic", "abc"); |
| 131 | + Assertions.assertFalse(MainApplication.validateConfiguration(properties)); |
| 132 | + |
| 133 | + } |
| 134 | + |
| 135 | +} |
0 commit comments