import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.lang.reflect.Field;
+import java.lang.reflect.InaccessibleObjectException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
}
}
+ /** This does not work in Java 17
try {
Field methodsField = HttpURLConnection.class.getDeclaredField("methods");
methodsField.setAccessible(true);
// remove the "final" modifier
modifiersField.setInt(methodsField, methodsField.getModifiers() & ~Modifier.FINAL);
- /* valid HTTP methods */
+ // valid HTTP methods
String[] methods = {
"GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE", "PATCH"
};
} catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) {
LOG.warn("Adding PATCH method", e);
}
+ **/
LOG.info("AAIResource.ctor initialized.");
}
LOG.info("AAIResource.ctor initialized.");
+ /* Not permitted in Java 17
try {
Field methodsField = HttpURLConnection.class.getDeclaredField("methods");
methodsField.setAccessible(true);
// remove the "final" modifier
modifiersField.setInt(methodsField, methodsField.getModifiers() & ~Modifier.FINAL);
- /* valid HTTP methods */
+ // valid HTTP methods
String[] methods = {
"GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE", "PATCH"
};
} catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) {
LOG.error("Exception occured", e);
}
+ */
}
<scope>provided</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <SDNC_CONFIG_DIR>${basedir}/src/test/resources</SDNC_CONFIG_DIR>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
@Test
public void testSqlResourceProvider() {
- try{
- Map<String, String> env = System.getenv();
- Class<?> cl = env.getClass();
- Field field = cl.getDeclaredField("m");
- field.setAccessible(true);
- Map<String, String> writableEnv = (Map<String, String>) field.get(env);
- writableEnv.put(SDNC_CONFIG_DIR, "./src/test/resources");
- } catch (Exception e) {
- throw new IllegalStateException("Failed to set environment variable", e);
- }
+
provider = new SqlResourcePropertiesProviderImpl();
assertNotNull(provider);
@Test
public void testReportSuccess() {
- try{
- Map<String, String> env = System.getenv();
- Class<?> cl = env.getClass();
- Field field = cl.getDeclaredField("m");
- field.setAccessible(true);
- Map<String, String> writableEnv = (Map<String, String>) field.get(env);
- writableEnv.put(SDNC_CONFIG_DIR, "./src/test/resources");
- } catch (Exception e) {
- throw new IllegalStateException("Failed to set environment variable", e);
- }
provider = new SqlResourcePropertiesProviderImpl();
Properties properties = provider.getProperties();
<DMAAP_AUTHKEY>ABC123</DMAAP_AUTHKEY>
<ODL_USER>admin</ODL_USER>
<ODL_PASSWORD>admin</ODL_PASSWORD>
+ <DMAAPLISTENERROOT>.</DMAAPLISTENERROOT>
</environmentVariables>
</configuration>
</plugin>
e.printStackTrace();
}
- try {
- Map<String, String> env = System.getenv();
- Class<?> cl = env.getClass();
- Field field = cl.getDeclaredField("m");
- field.setAccessible(true);
- Map<String, String> writableEnv = (Map<String, String>) field.get(env);
- writableEnv.put(DMAAPLISTENERROOT, ".");
- } catch (Exception e) {
- throw new IllegalStateException("Failed to set environment variable", e);
- }
+
Properties props = new Properties();
InputStream propStr = TestSdncEsrDmaapReceiver.class.getResourceAsStream("/dmaap-consumer-esrsysteminfo.properties");
e.printStackTrace();
}
- try {
- Map<String, String> env = System.getenv();
- Class<?> cl = env.getClass();
- Field field = cl.getDeclaredField("m");
- field.setAccessible(true);
- Map<String, String> writableEnv = (Map<String, String>) field.get(env);
- writableEnv.put(DMAAPLISTENERROOT, ".");
- } catch (Exception e) {
- throw new IllegalStateException("Failed to set environment variable", e);
- }
String msg = "{\n" +
" \"input\" : { \n" +
e.printStackTrace();
}
- try {
- Map<String, String> env = System.getenv();
- Class<?> cl = env.getClass();
- Field field = cl.getDeclaredField("m");
- field.setAccessible(true);
- Map<String, String> writableEnv = (Map<String, String>) field.get(env);
- writableEnv.put(DMAAPLISTENERROOT, ".");
- } catch (Exception e) {
- throw new IllegalStateException("Failed to set environment variable", e);
- }
-
String msg = "{\n" +
" \"input\" : { \n" +
" }\n" +
e.printStackTrace();
}
- try {
- Map<String, String> env = System.getenv();
- Class<?> cl = env.getClass();
- Field field = cl.getDeclaredField("m");
- field.setAccessible(true);
- Map<String, String> writableEnv = (Map<String, String>) field.get(env);
- writableEnv.put(DMAAPLISTENERROOT, ".");
- } catch (Exception e) {
- throw new IllegalStateException("Failed to set environment variable", e);
- }
Properties props = new Properties();
SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer();
DME2preferredRouterFilePath=src/test/resources/dmaap-listener.preferredRoute.txt
sdnc.odl.user=${ODL_USER}
sdnc.odl.password=${ODL_PASSWORD}
-sdnc.odl.url-base=http://localhost:8181/restconf/operations
\ No newline at end of file
+sdnc.odl.url-base=http://localhost:8181/restconf/operations
+routeOffer=MR1
\ No newline at end of file
sdnc.odl.user=${ODL_USER}
sdnc.odl.password=${ODL_PASSWORD}
sdnc.odl.url-base=http://localhost:8181/restconf/operations
+routeOffer=MR1
\ No newline at end of file
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>1.18.24</version>
+ </dependency>
</dependencies>
<build>
<environmentVariables>
<ODL_USER>admin</ODL_USER>
<ODL_PASSWORD>admin</ODL_PASSWORD>
+ <SDNC_CONFIG_DIR>src/test/resources</SDNC_CONFIG_DIR>
</environmentVariables>
</configuration>
</plugin>
<environmentVariables>
<ODL_USER>admin</ODL_USER>
<ODL_PASSWORD>admin</ODL_PASSWORD>
+ <SDNC_CONFIG_DIR>src/test/resources</SDNC_CONFIG_DIR>
</environmentVariables>
</configuration>
</plugin>
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.onap.ccsdk.sli.core.dblib.DBLibConnection;
import org.onap.ccsdk.sli.core.dblib.DbLibService;
import org.onap.ccsdk.sli.plugins.grtoolkit.data.ClusterActor;
DBLibConnection connection;
Properties properties;
- @Rule
- public final EnvironmentVariables environmentVariables = new EnvironmentVariables();
@Rule
public WireMockRule wireMockRule = new WireMockRule(9999);
@Before
public void setup() {
- environmentVariables.set("SDNC_CONFIG_DIR","src/test/resources");
dataBroker = mock(DataBroker.class);
notificationProviderService = mock(NotificationPublishService.class);
rpcProviderRegistry = mock(RpcProviderService.class);
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>com.github.stefanbirkner</groupId>
- <artifactId>system-rules</artifactId>
- <version>1.19.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.onap.ccsdk.sli.core</groupId>
<artifactId>sli-common</artifactId>
<artifactId>jettison</artifactId>
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <environmentVariables>
+ <deployer_pass>sdncp-123</deployer_pass>
+ </environmentVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
package jtest.org.onap.ccsdk.sli.plugins.prop;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
-
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.contrib.java.lang.system.EnvironmentVariables;
import static org.junit.Assert.assertEquals;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
public class TestPropertiesNode {
private static final Logger log = LoggerFactory.getLogger(TestPropertiesNode.class);
- @Rule
- public EnvironmentVariables environmentVariables = new EnvironmentVariables();
+
@Test
public void testJSONFileParsing() throws SvcLogicException {
@Test
public void testTXTFileParsing() throws SvcLogicException {
- environmentVariables.set("deployer_pass", "sdncp-123");
+
assertEquals("sdncp-123", System.getenv("deployer_pass"));
SvcLogicContext ctx = new SvcLogicContext();