Merge branch 'feature/mongo-seed' into 'master'
Mongo-seeding See merge request theappsmith/internal-tools-server!26
This commit is contained in:
commit
3a3521a539
|
|
@ -6,7 +6,6 @@
|
|||
image: docker:latest
|
||||
services:
|
||||
- docker:dind
|
||||
- mongo:latest
|
||||
|
||||
cache:
|
||||
paths:
|
||||
|
|
@ -28,7 +27,8 @@ stages:
|
|||
maven-build:
|
||||
image: maven:3-jdk-11-slim
|
||||
stage: build
|
||||
script: "mvn package -DskipTests -B"
|
||||
script:
|
||||
- mvn package -B -Dspring.profiles.active=local
|
||||
artifacts:
|
||||
paths:
|
||||
- appsmith-server/target/*.jar
|
||||
|
|
@ -45,7 +45,6 @@ docker-package:
|
|||
only:
|
||||
- master
|
||||
|
||||
|
||||
heroku-deploy:
|
||||
stage: deploy
|
||||
image: tmaier/dpl:latest
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.appsmith</groupId>
|
||||
<artifactId>interfaces</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<name>interfaces</name>
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.appsmith</groupId>
|
||||
<artifactId>appsmith-plugins</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>com.appsmith</groupId>
|
||||
<artifactId>server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>server</name>
|
||||
|
|
@ -96,6 +96,11 @@
|
|||
<artifactId>compiler</artifactId>
|
||||
<version>0.9.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.flapdoodle.embed</groupId>
|
||||
<artifactId>de.flapdoodle.embed.mongo</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Plugin dependencies -->
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -1,16 +1,29 @@
|
|||
package com.appsmith.server;
|
||||
|
||||
import com.appsmith.server.services.ApplicationServiceTest;
|
||||
import com.appsmith.server.services.LayoutServiceTest;
|
||||
import com.appsmith.server.services.OrganizationServiceTest;
|
||||
import com.appsmith.server.services.PageServiceTest;
|
||||
import com.appsmith.server.services.UserServiceTest;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@RunWith(Suite.class)
|
||||
@SpringBootTest
|
||||
@Suite.SuiteClasses({
|
||||
OrganizationServiceTest.class,
|
||||
ApplicationServiceTest.class,
|
||||
LayoutServiceTest.class,
|
||||
UserServiceTest.class,
|
||||
PageServiceTest.class,
|
||||
})
|
||||
public class ServerApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
assert(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
package com.appsmith.server.configurations;
|
||||
|
||||
import com.appsmith.server.domains.Application;
|
||||
import com.appsmith.server.domains.Organization;
|
||||
import com.appsmith.server.domains.Page;
|
||||
import com.appsmith.server.domains.User;
|
||||
import com.appsmith.server.domains.UserState;
|
||||
import com.appsmith.server.repositories.ApplicationRepository;
|
||||
import com.appsmith.server.repositories.OrganizationRepository;
|
||||
import com.appsmith.server.repositories.PageRepository;
|
||||
import com.appsmith.server.repositories.UserRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class SeedMongoData {
|
||||
|
||||
@Bean
|
||||
ApplicationRunner init(UserRepository userRepository,
|
||||
OrganizationRepository organizationRepository,
|
||||
ApplicationRepository applicationRepository,
|
||||
PageRepository pageRepository) {
|
||||
log.info("Seeding the data");
|
||||
Object[][] userData = {
|
||||
{"user test", "usertest@usertest.com", UserState.ACTIVATED},
|
||||
{"api_user", "api_user", UserState.ACTIVATED},
|
||||
};
|
||||
Object[][] orgData = {
|
||||
{"Spring Test Organization", "appsmith-spring-test.com", "appsmith.com"}
|
||||
};
|
||||
Object[][] appData = {
|
||||
{"LayoutServiceTest TestApplications"}
|
||||
};
|
||||
Object[][] pageData = {
|
||||
{"validPageName"}
|
||||
};
|
||||
return args -> {
|
||||
organizationRepository.deleteAll()
|
||||
.thenMany(
|
||||
// Seed the organization data into the DB
|
||||
Flux.just(orgData)
|
||||
.map(array -> {
|
||||
Organization organization = new Organization();
|
||||
organization.setName((String) array[0]);
|
||||
organization.setDomain((String) array[1]);
|
||||
organization.setWebsite((String) array[2]);
|
||||
return organization;
|
||||
}).flatMap(organizationRepository::save)
|
||||
)
|
||||
// Query the seed data to get the organizationId (required for application creation)
|
||||
.then(organizationRepository.findByName((String) orgData[0][0]))
|
||||
.map(org -> org.getId())
|
||||
// Seed the user data into the DB
|
||||
.flatMapMany(orgId -> Flux.just(userData)
|
||||
.map(array -> {
|
||||
User user = new User();
|
||||
user.setName((String) array[0]);
|
||||
user.setEmail((String) array[1]);
|
||||
user.setState((UserState) array[2]);
|
||||
user.setOrganizationId(orgId);
|
||||
return user;
|
||||
})
|
||||
.flatMap(userRepository::save)
|
||||
.then(Mono.just(orgId))
|
||||
).flatMap(orgId ->
|
||||
// Seed the application data into the DB
|
||||
Flux.just(appData).map(array -> {
|
||||
Application app = new Application();
|
||||
app.setName((String) array[0]);
|
||||
app.setOrganizationId(orgId);
|
||||
return app;
|
||||
}).flatMap(applicationRepository::save)
|
||||
// Query the seed data to get the applicationId (required for page creation)
|
||||
).then(applicationRepository.findByName((String) appData[0][0]))
|
||||
.map(application -> application.getId())
|
||||
.flatMapMany(appId -> Flux.just(pageData)
|
||||
// Seed the page data into the DB
|
||||
.map(array -> {
|
||||
Page page = new Page();
|
||||
page.setName((String) array[0]);
|
||||
page.setApplicationId(appId);
|
||||
return page;
|
||||
})
|
||||
.flatMap(pageRepository::save)
|
||||
).subscribe(obj -> log.info("Last Saved Object: " + obj));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -8,13 +8,16 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_CLASS;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import org.junit.runner.RunWith;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
|
@ -22,6 +23,7 @@ import reactor.test.StepVerifier;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_CLASS;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
|
|
@ -41,15 +43,8 @@ public class LayoutServiceTest {
|
|||
Mono<Application> applicationMono;
|
||||
|
||||
@Before
|
||||
@WithMockUser(username = "api_user")
|
||||
public void setup() {
|
||||
|
||||
Application testApplication = new Application();
|
||||
testApplication.setName("LayoutServiceTest TestApplications");
|
||||
applicationMono =
|
||||
applicationService.findByName(testApplication.getName())
|
||||
.switchIfEmpty(applicationService.create(testApplication));
|
||||
|
||||
applicationMono = applicationService.findByName("LayoutServiceTest TestApplications");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -157,15 +152,9 @@ public class LayoutServiceTest {
|
|||
testLayout.setDsl(obj);
|
||||
|
||||
Page testPage = new Page();
|
||||
testPage.setName("LayoutServiceTest updateLayoutValidPage");
|
||||
testPage.setName("validPageName");
|
||||
Page page = pageService
|
||||
.findByName(testPage.getName())
|
||||
.switchIfEmpty(applicationMono
|
||||
.map(application -> {
|
||||
testPage.setApplicationId(application.getId());
|
||||
return testPage;
|
||||
})
|
||||
.flatMap(pageService::save))
|
||||
.block();
|
||||
|
||||
Layout startLayout = layoutService.createLayout(page.getId(), testLayout).block();
|
||||
|
|
|
|||
|
|
@ -9,11 +9,13 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_CLASS;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
|
|
|
|||
|
|
@ -13,11 +13,13 @@ import org.junit.runner.RunWith;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_CLASS;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
|
|
|
|||
|
|
@ -10,11 +10,14 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_CLASS;
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
|
|
@ -31,22 +34,9 @@ public class UserServiceTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
//User init
|
||||
User user = new User();
|
||||
user.setName("user test");
|
||||
user.setEmail("usertest@usertest.com");
|
||||
user.setState(UserState.ACTIVATED);
|
||||
//Store the user in case its not present in the database.
|
||||
userMono = userService.findByEmail("usertest@usertest.com").switchIfEmpty(Mono.defer(() -> userService.save(user)));
|
||||
|
||||
//Organization init
|
||||
Organization organization = new Organization();
|
||||
organization.setName("Spring Test Organization");
|
||||
organization.setDomain("appsmith-spring-test.com");
|
||||
organization.setWebsite("appsmith.com");
|
||||
|
||||
//Store the organization in case its not present in the database.
|
||||
organizationMono = organizationService.getByName("Spring Test Organization").switchIfEmpty(Mono.defer(() -> organizationService.save(organization)));
|
||||
userMono = userService.findByEmail("usertest@usertest.com");
|
||||
organizationMono = organizationService.getByName("Spring Test Organization");
|
||||
}
|
||||
|
||||
//Test the update organization flow.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
# Jackson Properties
|
||||
spring.jackson.default-property-inclusion=non_null
|
||||
|
||||
#Mongo properties
|
||||
spring.data.mongodb.database=mobtools
|
||||
spring.data.mongodb.host=localhost
|
||||
spring.data.mongodb.port=27017
|
||||
#spring.data.mongodb.username=
|
||||
#spring.data.mongodb.password=
|
||||
|
||||
logging.level.root=INFO
|
||||
logging.level.com.appsmith=debug
|
||||
logging.pattern.console=%X - %m%n
|
||||
|
||||
#Spring security
|
||||
spring.security.oauth2.client.registration.google.client-id=869021686091-9b84bbf7ea683t1aaefqnmefcnmk6fq6.apps.googleusercontent.com
|
||||
spring.security.oauth2.client.registration.google.client-secret=9dvITt4OayEY1HfeY8bHX74p
|
||||
|
||||
# Accounts from specific domains are allowed to login
|
||||
oauth2.allowed-domains=appsmith.com
|
||||
|
|
@ -17,6 +17,15 @@ services:
|
|||
networks:
|
||||
- appsmith
|
||||
|
||||
mongo_seed:
|
||||
image: appsmith-mongo
|
||||
links:
|
||||
- mongo
|
||||
volumes:
|
||||
- ./mongo-seed:/mongo-seed
|
||||
networks:
|
||||
- appsmith
|
||||
|
||||
networks:
|
||||
appsmith:
|
||||
driver: bridge
|
||||
Loading…
Reference in New Issue
Block a user