Skip to content
Permalink
Browse files
Updating test environment. Created three suites. One for each example…
… application used to test anubis. Once the test environment is changed so applications don't all try to use 9090, it will be possible to create a single suite.
  • Loading branch information
myrle-krantz committed Jul 31, 2017
1 parent 1f511a5 commit e2f812cc1727520f81cd4896978aef0621b59f29
Showing 15 changed files with 393 additions and 382 deletions.

This file was deleted.

@@ -13,67 +13,58 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.mifos.anubis;

import io.mifos.anubis.api.v1.domain.ApplicationSignatureSet;
import io.mifos.anubis.example.noinitialize.ExampleConfiguration;
import io.mifos.anubis.test.v1.TenantApplicationSecurityEnvironmentTestRule;
import io.mifos.core.test.env.TestEnvironment;
import io.mifos.anubis.example.noinitialize.Example;
import io.mifos.core.test.fixture.TenantDataStoreContextTestRule;
import io.mifos.core.test.fixture.cassandra.CassandraInitializer;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
import io.mifos.anubis.suites.SuiteTestEnvironment;

/**
* @author Myrle Krantz
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class TestAnubisInitializeWithoutServiceBacking {
private static final String APP_NAME = "anubis-v1";

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
classes = AbstractNoInitializeTest.TestConfiguration.class)
public class AbstractNoInitializeTest extends SuiteTestEnvironment {
private static final String LOGGER_QUALIFIER = "test-logger";
@Configuration
@EnableFeignClients(basePackages = {"io.mifos.anubis.example.noinitialize"})
@RibbonClient(name = APP_NAME)
@Import({ExampleConfiguration.class})
static public class TestConfiguration {
public TestConfiguration() {
super();
}

@Bean()
@Bean(name = LOGGER_QUALIFIER)
public Logger logger() {
return LoggerFactory.getLogger("initialize-without-rest-definition-test-logger");
return LoggerFactory.getLogger(APP_NAME + "-logger");
}
}

@ClassRule
public final static TestEnvironment testEnvironment = new TestEnvironment(APP_NAME);
@SuppressWarnings({"SpringAutowiredFieldsWarningInspection", "SpringJavaAutowiringInspection"})
@Autowired
Example example;

@ClassRule
public final static CassandraInitializer cassandraInitializer = new CassandraInitializer();
@SuppressWarnings({"SpringAutowiredFieldsWarningInspection", "SpringJavaAutowiringInspection"})
@Autowired
@Qualifier(value = LOGGER_QUALIFIER)
Logger logger;

@Rule
public final TenantDataStoreContextTestRule tenantDataStoreContext = TenantDataStoreContextTestRule.forRandomTenantName(cassandraInitializer);

@Test
public void test()
{
final TenantApplicationSecurityEnvironmentTestRule tenantApplicationSecurityEnvironment
= new TenantApplicationSecurityEnvironmentTestRule(testEnvironment);

final ApplicationSignatureSet applicationSignatureSet
= tenantApplicationSecurityEnvironment.initializeTenantInApplication();
for (int i = 0; i < 50; i++ ) {
final ApplicationSignatureSet x = tenantApplicationSecurityEnvironment.initializeTenantInApplication();
Assert.assertEquals(applicationSignatureSet, x);
}
}
}
@@ -13,37 +13,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import io.mifos.anubis.example.nokeystorage.Example;
package io.mifos.anubis;

import io.mifos.anubis.example.nokeystorage.ExampleConfiguration;
import io.mifos.anubis.test.v1.SystemSecurityEnvironment;
import io.mifos.core.api.context.AutoSeshat;
import io.mifos.core.lang.AutoTenantContext;
import io.mifos.core.lang.TenantContextHolder;
import io.mifos.core.test.env.TestEnvironment;
import io.mifos.anubis.example.nokeystorage.Example;
import io.mifos.core.test.fixture.TenantDataStoreContextTestRule;
import io.mifos.core.test.fixture.cassandra.CassandraInitializer;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
import io.mifos.anubis.suites.SuiteTestEnvironment;

/**
* @author Myrle Krantz
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class TestAnubisInitializeWithSpecialTenantSignatureRepository {
private static final String APP_NAME = "anubis-v1";
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
classes = AbstractNoKeyStorageTest.TestConfiguration.class)
public class AbstractNoKeyStorageTest extends SuiteTestEnvironment {
private static final String LOGGER_QUALIFIER = "test-logger";

@Configuration
@EnableFeignClients(basePackages = {"io.mifos.anubis.example.nokeystorage"})
@@ -54,38 +51,21 @@ public TestConfiguration() {
super();
}

@Bean()
@Bean(name = LOGGER_QUALIFIER)
public Logger logger() {
return LoggerFactory.getLogger("initialize-with-special-tenant-signature-repository-test-logger");
return LoggerFactory.getLogger(APP_NAME + "-logger");
}
}

@ClassRule
public final static TestEnvironment testEnvironment = new TestEnvironment(APP_NAME);
@SuppressWarnings({"SpringAutowiredFieldsWarningInspection", "SpringJavaAutowiringInspection"})
@Autowired
Example example;

@ClassRule
public final static CassandraInitializer cassandraInitializer = new CassandraInitializer();
@SuppressWarnings({"SpringAutowiredFieldsWarningInspection", "SpringJavaAutowiringInspection"})
@Autowired
@Qualifier(value = LOGGER_QUALIFIER)
Logger logger;

@Rule
public final TenantDataStoreContextTestRule tenantDataStoreContext = TenantDataStoreContextTestRule.forRandomTenantName(cassandraInitializer);

@SuppressWarnings({"SpringAutowiredFieldsWarningInspection", "SpringJavaAutowiredMembersInspection"})
@Autowired
protected Example example;

@Test
public void test()
{
final SystemSecurityEnvironment systemSecurityEnvironment = new SystemSecurityEnvironment(
testEnvironment.getSystemKeyTimestamp(),
testEnvironment.getSystemPublicKey(),
testEnvironment.getSystemPrivateKey());

final String systemToken = systemSecurityEnvironment.systemToken(APP_NAME);

try (final AutoTenantContext ignored = new AutoTenantContext(TenantContextHolder.checkedGetIdentifier())) {
try (final AutoSeshat ignored2 = new AutoSeshat(systemToken)) {
example.initialize();
}}
}
}
@@ -0,0 +1,77 @@
/*
* Copyright 2017 The Mifos Initiative.
*
* Licensed 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 io.mifos.anubis;

import io.mifos.anubis.example.simple.Example;
import io.mifos.anubis.example.simple.ExampleConfiguration;
import io.mifos.anubis.test.v1.TenantApplicationSecurityEnvironmentTestRule;
import io.mifos.core.test.fixture.TenantDataStoreContextTestRule;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
import io.mifos.anubis.suites.SuiteTestEnvironment;

/**
* @author Myrle Krantz
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
classes = AbstractSimpleTest.TestConfiguration.class)
public class AbstractSimpleTest extends SuiteTestEnvironment {
private static final String LOGGER_QUALIFIER = "test-logger";

@Configuration
@EnableFeignClients(basePackages = {"io.mifos.anubis.example.simple"})
@RibbonClient(name = APP_NAME)
@Import({ExampleConfiguration.class})
public static class TestConfiguration {
public TestConfiguration() {
super();
}

@Bean(name = LOGGER_QUALIFIER)
public Logger logger() {
return LoggerFactory.getLogger(APP_NAME + "-logger");
}
}

@SuppressWarnings({"SpringAutowiredFieldsWarningInspection", "SpringJavaAutowiringInspection"})
@Autowired
Example example;

@SuppressWarnings({"SpringAutowiredFieldsWarningInspection", "SpringJavaAutowiringInspection"})
@Autowired
@Qualifier(value = LOGGER_QUALIFIER)
Logger logger;

@ClassRule
public final static TenantDataStoreContextTestRule tenantDataStoreContext = TenantDataStoreContextTestRule.forRandomTenantName(cassandraInitializer);

@Rule
public final TenantApplicationSecurityEnvironmentTestRule tenantApplicationSecurityEnvironment
= new TenantApplicationSecurityEnvironmentTestRule(testEnvironment);
}

0 comments on commit e2f812c

Please sign in to comment.