Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/base data mssql imperative with sample #1

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions data/data-samples/sample-data-mssql-book/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2020 American Express Travel Related Services Company, Inc.

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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>data-samples</artifactId>
<version>0.3.32-SNAPSHOT</version>
</parent>

<artifactId>sample-data-mssql-book</artifactId>

<dependencies>
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-data-mssql</artifactId>
<exclusions>
<exclusion>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-mssql</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-framework-test</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2020 American Express Travel Related Services Company, Inc.
*
* 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.americanexpress.data.mssql.book.config;

import io.americanexpress.synapse.data.mssql.config.BaseMicrosoftSQLDataConfig;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;

/**
* {@code BookDataConfig} contains configurations for connecting to Mssql database.
*/
@Configuration
@EnableAutoConfiguration
@EnableJpaRepositories(basePackages = "io.americanexpress.data.mssql.book")
@PropertySource("classpath:data-mssql-book-application.properties")
public class BookDataConfig extends BaseMicrosoftSQLDataConfig {

/**
* Scans package string.
*/
private static final String PACKAGE_SCAN_NAME = "io.americanexpress.data.mssql.book.entity";

/**
* Instantiates a new Book data config.
*
* @param environment the environment
*/
protected BookDataConfig(Environment environment) {
super(environment);
}

/**
* Scans package containing jpa entity.
* @param entityManagerFactoryBean the entity manager factory bean
*/
@Override
protected void setPackagesToScan(
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean) {
entityManagerFactoryBean.setPackagesToScan(PACKAGE_SCAN_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2020 American Express Travel Related Services Company, Inc.
*
* 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.americanexpress.data.mssql.book.entity;

import io.americanexpress.synapse.data.mssql.entity.BaseEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;

/**
* The type Book entity.
*/
@Entity
@Table(name = "book")
public class BookEntity extends BaseEntity {

/**
* The book title.
*/
private String title;

/**
* The book author.
*/
private String author;

/**
* Gets title.
*
* @return the title
*/
public String getTitle() {
return title;
}

/**
* Sets title.
*
* @param title the title
*/
public void setTitle(String title) {
this.title = title;
}

/**
* Gets author.
*
* @return the author
*/
public String getAuthor() {
return author;
}

/**
* Sets author.
*
* @param author the author
*/
public void setAuthor(String author) {
this.author = author;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020 American Express Travel Related Services Company, Inc.
*
* 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.americanexpress.data.mssql.book.repository;

import io.americanexpress.data.mssql.book.entity.BookEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

/**
* {@code BookRepository} contains methods for accessing Book table in Mssql database.
*/
@Repository
public interface BookRepository extends JpaRepository<BookEntity, Long> {

/**
* Finds A Book Entity in the database by title and author.
* @param title of the book.
* @param author of the book.
* @return A BookEntity of the provided title and author.
*/
BookEntity findByTitleAndAuthor(String title, String author);

/**
* Finds a Book Entity in the database by title.
* @param title of the book.
* @return A BookEntity of the provided title.
*/
BookEntity findByTitle(String title);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 American Express Travel Related Services Company, Inc.
#
# 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.

spring.mssql.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=tempdb;trustServerCertificate=true;
spring.mssql.datasource.username=sa
spring.mssql.datasource.password=
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2020 American Express Travel Related Services Company, Inc.
*
* 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.
*/

SET
SCHEMA_SEARCH_PATH TO synapse;

INSERT INTO book (title, author, created_date_time, last_modified_date_time, created_by, last_modified_by, version)
VALUES ('Synapse', 'Gabriel', GETDATE(), GETDATE(), '[email protected]', '[email protected]', 0);

INSERT INTO book (title, author, created_date_time, last_modified_date_time, created_by, last_modified_by, version)
VALUES ('Revenge of Synapse', 'John', GETDATE(), GETDATE(), '[email protected]', '[email protected]', 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- Copyright 2020 American Express Travel Related Services Company, Inc.
--
-- 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.

DROP SCHEMA IF EXISTS synapse CASCADE;
CREATE SCHEMA synapse;

SET
SCHEMA_SEARCH_PATH TO synapse;

DROP TABLE IF EXISTS book CASCADE;

CREATE TABLE book (
id INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
title NVARCHAR(150) NOT NULL UNIQUE,
author NVARCHAR(100),
created_by NVARCHAR(100),
last_modified_by NVARCHAR(100),
created_date_time DATETIME DEFAULT GETDATE(),
last_modified_date_time DATETIME,
version INT NOT NULL
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2020 American Express Travel Related Services Company, Inc.
*
* 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.americanexpress.data.mssql.book.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
* {@code BookDataTestConfig} class contains configurations for tests.
*/
@Configuration
@Import(BookDataConfig.class)
public class BookDataTestConfig {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2020 American Express Travel Related Services Company, Inc.
*
* 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.americanexpress.data.mssql.book.repository;

import io.americanexpress.data.mssql.book.config.BookDataTestConfig;
import io.americanexpress.data.mssql.book.entity.BookEntity;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* {@code BookRepositoryIT} tests the {@link BookRepository} with local instance of Mssql database.
*/
@ContextConfiguration(classes = BookDataTestConfig.class)
@ExtendWith(SpringExtension.class)
class BookRepositoryIT {

/**
* Book repository.
*/
@Autowired
private BookRepository bookRepository;

/**
* Find All test.
*/
@Test
void findAll_givenBooksInDatabase_expectedBooksReturned() {
List<BookEntity> bookEntityList = bookRepository.findAll();
assertEquals(bookEntityList.size(), 2);
}

/**
* Find by title test.
*/
@Test
void findBookByTitle_givenTitleInDatabase_expectedBookByTitleReturned() {
BookEntity bookRepositoryByTitle = bookRepository.findByTitle("Revenge of Synapse");
assertNotNull(bookRepositoryByTitle);
}
}
4 changes: 4 additions & 0 deletions data/synapse-data-mssql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-mssql</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>

<!--Spring-->
<dependency>
Expand Down
Loading