From 30bade80dfb9ba456a6b019a2c03b19ad02a704f Mon Sep 17 00:00:00 2001 From: Yiming Liu Date: Sat, 12 Mar 2016 13:19:32 +0800 Subject: [PATCH] Add portal test configuration --- .gitignore | 6 +++- .../src/test/resources/data.sql | 0 .../src/test/resources/schema.sql | 0 .../portal/controller/AppController.java | 10 ++---- .../PortalApplicationTestConfiguration.java | 8 +++++ .../portal/repository/AppRepositoryTest.java | 35 +++++++++++++++++++ apollo-portal/src/test/resources/data.sql | 0 apollo-portal/src/test/resources/schema.sql | 0 pom.xml | 2 +- 9 files changed, 52 insertions(+), 9 deletions(-) delete mode 100644 apollo-configserver/src/test/resources/data.sql delete mode 100644 apollo-configserver/src/test/resources/schema.sql create mode 100644 apollo-portal/src/test/java/com/ctrip/apollo/portal/PortalApplicationTestConfiguration.java create mode 100644 apollo-portal/src/test/java/com/ctrip/apollo/portal/repository/AppRepositoryTest.java delete mode 100644 apollo-portal/src/test/resources/data.sql delete mode 100644 apollo-portal/src/test/resources/schema.sql diff --git a/.gitignore b/.gitignore index d33905fd3..9136753b5 100644 --- a/.gitignore +++ b/.gitignore @@ -11,8 +11,12 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +# Eclipse .classpath .project target - .settings + +# Idea +.idea +*.iml \ No newline at end of file diff --git a/apollo-configserver/src/test/resources/data.sql b/apollo-configserver/src/test/resources/data.sql deleted file mode 100644 index e69de29bb..000000000 diff --git a/apollo-configserver/src/test/resources/schema.sql b/apollo-configserver/src/test/resources/schema.sql deleted file mode 100644 index e69de29bb..000000000 diff --git a/apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java b/apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java index c697a30ff..b238603a0 100644 --- a/apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java +++ b/apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java @@ -26,12 +26,8 @@ public class AppController { } @RequestMapping(value = "", method = RequestMethod.POST) - public App create() { - App ramdomApp = new App(); - ramdomApp.setId(String.valueOf(System.currentTimeMillis())); - ramdomApp.setName("new app " + System.currentTimeMillis()); - ramdomApp.setOwner("owner " + System.currentTimeMillis()); - ramdomApp.setCreateTimestamp(new Date()); - return appRepository.save(ramdomApp); + public App create(App app) { + app.setCreateTimestamp(new Date()); + return appRepository.save(app); } } diff --git a/apollo-portal/src/test/java/com/ctrip/apollo/portal/PortalApplicationTestConfiguration.java b/apollo-portal/src/test/java/com/ctrip/apollo/portal/PortalApplicationTestConfiguration.java new file mode 100644 index 000000000..42edfd3ef --- /dev/null +++ b/apollo-portal/src/test/java/com/ctrip/apollo/portal/PortalApplicationTestConfiguration.java @@ -0,0 +1,8 @@ +package com.ctrip.apollo.portal; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class PortalApplicationTestConfiguration { + +} diff --git a/apollo-portal/src/test/java/com/ctrip/apollo/portal/repository/AppRepositoryTest.java b/apollo-portal/src/test/java/com/ctrip/apollo/portal/repository/AppRepositoryTest.java new file mode 100644 index 000000000..467361790 --- /dev/null +++ b/apollo-portal/src/test/java/com/ctrip/apollo/portal/repository/AppRepositoryTest.java @@ -0,0 +1,35 @@ +package com.ctrip.apollo.portal.repository; + +import java.util.Date; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.ctrip.apollo.portal.PortalApplicationTestConfiguration; +import com.ctrip.apollo.portal.entities.App; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = PortalApplicationTestConfiguration.class) +public class AppRepositoryTest { + + @Autowired + AppRepository repository; + + @Test + public void testCreate() { + Assert.assertEquals(0, repository.count()); + + App ramdomApp = new App(); + ramdomApp.setId(String.valueOf(System.currentTimeMillis())); + ramdomApp.setName("new app " + System.currentTimeMillis()); + ramdomApp.setOwner("owner " + System.currentTimeMillis()); + ramdomApp.setCreateTimestamp(new Date()); + repository.save(ramdomApp); + + Assert.assertEquals(1, repository.count()); + } +} diff --git a/apollo-portal/src/test/resources/data.sql b/apollo-portal/src/test/resources/data.sql deleted file mode 100644 index e69de29bb..000000000 diff --git a/apollo-portal/src/test/resources/schema.sql b/apollo-portal/src/test/resources/schema.sql deleted file mode 100644 index e69de29bb..000000000 diff --git a/pom.xml b/pom.xml index b7311abdc..538247044 100644 --- a/pom.xml +++ b/pom.xml @@ -99,7 +99,7 @@ org.eluder.coveralls coveralls-maven-plugin - 3.1.0 + 4.1.0 -- GitLab