You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ju...@apache.org on 2019/10/16 20:03:20 UTC
[fineract-cn-template] 07/45: Provided example necessary for
running multiple tests as a suite. This is a pre-req for continuous
integration.
This is an automated email from the ASF dual-hosted git repository.
juhan pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-template.git
commit 15528625ed719bc3350f337f0f59b6e3e0ff7f4f
Author: Myrle Krantz <my...@apache.org>
AuthorDate: Mon Jul 10 11:51:53 2017 +0200
Provided example necessary for running multiple tests as a suite. This
is a pre-req for continuous integration.
---
.../io/mifos/template/SuiteTestEnvironment.java | 43 ++++++++++++++++++++++
.../main/java/io/mifos/template/TestSample.java | 34 +++++++----------
.../src/main/java/io/mifos/template/TestSuite.java | 27 ++++++++++++++
3 files changed, 84 insertions(+), 20 deletions(-)
diff --git a/component-test/src/main/java/io/mifos/template/SuiteTestEnvironment.java b/component-test/src/main/java/io/mifos/template/SuiteTestEnvironment.java
new file mode 100644
index 0000000..dd5bfd0
--- /dev/null
+++ b/component-test/src/main/java/io/mifos/template/SuiteTestEnvironment.java
@@ -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));
+}
diff --git a/component-test/src/main/java/io/mifos/template/TestSample.java b/component-test/src/main/java/io/mifos/template/TestSample.java
index b829355..9e90129 100644
--- a/component-test/src/main/java/io/mifos/template/TestSample.java
+++ b/component-test/src/main/java/io/mifos/template/TestSample.java
@@ -17,10 +17,7 @@ package io.mifos.template;
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.api.v1.domain.Sample;
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 @@ import java.util.List;
@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 class TestSample {
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 class TestSample {
@Autowired
private EventRecorder eventRecorder;
+ @SuppressWarnings("WeakerAccess")
+ @Autowired
+ @Qualifier(LOGGER_NAME)
+ Logger logger;
+
public TestSample() {
super();
}
@@ -119,6 +111,7 @@ public class TestSample {
@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 class TestSample {
@Test
public void shouldListSamples() {
+ logger.info("Running test shouldListSamples.");
final List<Sample> allEntities = this.testSubject.findAllEntities();
Assert.assertNotNull(allEntities);
}
diff --git a/component-test/src/main/java/io/mifos/template/TestSuite.java b/component-test/src/main/java/io/mifos/template/TestSuite.java
new file mode 100644
index 0000000..44ed340
--- /dev/null
+++ b/component-test/src/main/java/io/mifos/template/TestSuite.java
@@ -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 {
+}