Skip to content
Permalink
Browse files
Provided example necessary for running multiple tests as a suite. This
is a pre-req for continuous integration.
  • Loading branch information
myrle-krantz committed Jul 10, 2017
1 parent d9745aa commit 15528625ed719bc3350f337f0f59b6e3e0ff7f4f
Showing 3 changed files with 84 additions and 20 deletions.
@@ -0,0 +1,43 @@
/*
* 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.template;

import io.mifos.core.test.env.TestEnvironment;
import io.mifos.core.test.fixture.cassandra.CassandraInitializer;
import io.mifos.core.test.fixture.mariadb.MariaDBInitializer;
import org.junit.ClassRule;
import org.junit.rules.RuleChain;
import org.junit.rules.RunExternalResourceOnce;
import org.junit.rules.TestRule;

/**
* This contains the database resources required by the test. They are in a separate
* class so that the test suite can initialize them before the classes it calls. This
* makes test runs faster and prevents tests from "stepping on each other's toes" when
* initializing and de-initializing external resources.
*/
public class SuiteTestEnvironment {
static final String APP_NAME = "template-v1";
static final TestEnvironment testEnvironment = new TestEnvironment(APP_NAME);
static final CassandraInitializer cassandraInitializer = new CassandraInitializer();
static final MariaDBInitializer mariaDBInitializer = new MariaDBInitializer();

@ClassRule
public static TestRule orderClassRules = RuleChain
.outerRule(new RunExternalResourceOnce(testEnvironment))
.around(new RunExternalResourceOnce(cassandraInitializer))
.around(new RunExternalResourceOnce(mariaDBInitializer));
}
@@ -17,10 +17,7 @@

import io.mifos.anubis.test.v1.TenantApplicationSecurityEnvironmentTestRule;
import io.mifos.core.api.context.AutoUserContext;
import io.mifos.core.test.env.TestEnvironment;
import io.mifos.core.test.fixture.TenantDataStoreContextTestRule;
import io.mifos.core.test.fixture.cassandra.CassandraInitializer;
import io.mifos.core.test.fixture.mariadb.MariaDBInitializer;
import io.mifos.core.test.listener.EnableEventRecording;
import io.mifos.core.test.listener.EventRecorder;
import io.mifos.template.api.v1.EventConstants;
@@ -29,12 +26,11 @@
import io.mifos.template.service.TemplateConfiguration;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.*;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
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;
@@ -48,9 +44,10 @@

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class TestSample {
public class TestSample extends SuiteTestEnvironment {
private static final String LOGGER_NAME = "test-logger";
private static final String TEST_USER = "homer";

private static final String APP_NAME = "template-v1";

@Configuration
@EnableEventRecording
@@ -63,24 +60,14 @@ public TestConfiguration() {
super();
}

@Bean()
@Bean(name = LOGGER_NAME)
public Logger logger() {
return LoggerFactory.getLogger("test-logger");
return LoggerFactory.getLogger(LOGGER_NAME);
}
}
private static final String TEST_USER = "homer";

private final static TestEnvironment testEnvironment = new TestEnvironment(APP_NAME);
private final static CassandraInitializer cassandraInitializer = new CassandraInitializer();
private final static MariaDBInitializer mariaDBInitializer = new MariaDBInitializer();
private final static TenantDataStoreContextTestRule tenantDataStoreContext = TenantDataStoreContextTestRule.forRandomTenantName(cassandraInitializer, mariaDBInitializer);

@ClassRule
public static TestRule orderClassRules = RuleChain
.outerRule(testEnvironment)
.around(cassandraInitializer)
.around(mariaDBInitializer)
.around(tenantDataStoreContext);
public final static TenantDataStoreContextTestRule tenantDataStoreContext = TenantDataStoreContextTestRule.forRandomTenantName(cassandraInitializer, mariaDBInitializer);

@Rule
public final TenantApplicationSecurityEnvironmentTestRule tenantApplicationSecurityEnvironment
@@ -94,6 +81,11 @@ public Logger logger() {
@Autowired
private EventRecorder eventRecorder;

@SuppressWarnings("WeakerAccess")
@Autowired
@Qualifier(LOGGER_NAME)
Logger logger;

public TestSample() {
super();
}
@@ -119,6 +111,7 @@ public boolean waitForInitialize() {

@Test
public void shouldCreateSample() throws InterruptedException {
logger.info("Running test shouldCreateSample.");
final Sample sample = Sample.create(RandomStringUtils.randomAlphanumeric(8), RandomStringUtils.randomAlphanumeric(512));
this.testSubject.createEntity(sample);

@@ -130,6 +123,7 @@ public void shouldCreateSample() throws InterruptedException {

@Test
public void shouldListSamples() {
logger.info("Running test shouldListSamples.");
final List<Sample> allEntities = this.testSubject.findAllEntities();
Assert.assertNotNull(allEntities);
}
@@ -0,0 +1,27 @@
/*
* 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.template;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({
TestSample.class,
//TODO: when you create a new component test, add it here so you can run it with the suite.
})
public class TestSuite extends SuiteTestEnvironment {
}

0 comments on commit 1552862

Please sign in to comment.