Skip to content

Commit

Permalink
migrate spring cloud sample repo (Azure#14076)
Browse files Browse the repository at this point in the history
* sample repo initiation

* migrate spring cloud sample repo

* remove duplicate dependency mangement

* sync spring cloud repo update

* fix readme broken link;sync storage & integration module code;

* fix readme broken link

* fix readme broken link

* fix error

* fix build errors
  • Loading branch information
moarychan authored Aug 19, 2020
1 parent 958705c commit 6d0907b
Show file tree
Hide file tree
Showing 199 changed files with 8,519 additions and 8 deletions.
1 change: 1 addition & 0 deletions eng/versioning/external_dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ org.springframework.boot:spring-boot-starter-actuator;2.3.3.RELEASE
org.springframework.boot:spring-boot-starter-aop;2.3.3.RELEASE
org.springframework.boot:spring-boot-starter-cache;2.3.3.RELEASE
org.springframework.boot:spring-boot-starter-data-redis;2.3.3.RELEASE
org.springframework.boot:spring-boot-starter-logging;2.3.3.RELEASE
org.springframework.boot:spring-boot-starter-parent;2.3.0.RELEASE
org.springframework.boot:spring-boot-starter-test;2.3.3.RELEASE
org.springframework.boot:spring-boot-starter-validation;2.3.3.RELEASE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Release History

## 1.2.8-beta.1 (Unreleased)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Azure Spring Cloud App Configuration Conversion Sample client library for Java

## Key concepts
## Getting started
## Key concepts
## Examples
## Troubleshooting
## Next steps
## Contributing
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version> <!-- {x-version-update;org.springframework.boot:spring-boot-starter-parent;external_dependency} -->
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-cloud-azure-appconfiguration-convert-sample-complete</artifactId>
<groupId>com.microsoft.azure</groupId>
<version>1.2.8-beta.1</version> <!-- {x-version-update;com.microsoft.azure:spring-cloud-azure-appconfiguration-convert-sample-complete;current} -->
<name>Azure Spring Cloud App Configuration Conversion Sample</name>
<description>Sample project to show conversion to Azure App Configuration</description>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR7</version> <!-- {x-version-update;org.springframework.cloud:spring-cloud-dependencies;external_dependency} -->
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-cosmosdb-spring-boot-starter</artifactId>
<version>2.3.3</version> <!-- {x-version-update;com.microsoft.azure:azure-cosmosdb-spring-boot-starter;dependency} -->
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.0-jre</version> <!-- {x-version-update;cosmos_com.google.guava:guava;external_dependency} -->
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>spring-cloud-starter-azure-appconfiguration-config</artifactId>
<version>1.2.8-beta.1</version> <!-- {x-version-update;com.microsoft.azure:spring-cloud-starter-azure-appconfiguration-config;current} -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version> <!-- {x-version-update;org.powermock:powermock-api-mockito2;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version> <!-- {x-version-update;org.powermock:powermock-module-junit4;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package sample.convert;

import java.util.Optional;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.Assert;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@SpringBootApplication
public class ConvertSampleApplication implements CommandLineRunner {

private static final Logger LOGGER = LoggerFactory.getLogger(ConvertSampleApplication.class);

@Autowired
private UserRepository repository;

public static void main(String[] args) {
SpringApplication.run(ConvertSampleApplication.class, args);
}

public void run(String... var1) throws Exception {

final User testUser = new User("testId", "testFirstName", "testLastName",
"test address line one");

// Save the User class to Azure CosmosDB database.
final Mono<User> saveUserMono = repository.save(testUser);

final Flux<User> firstNameUserFlux = repository.findByFirstName("testFirstName");

// Nothing happens until we subscribe to these Monos.
// findById will not return the user as user is not present.
final Mono<User> findByIdMono = repository.findById(testUser.getId());
final User findByIdUser = findByIdMono.block();
Assert.isNull(findByIdUser, "User must be null");

final User savedUser = saveUserMono.block();
Assert.state(savedUser != null,
"Saved user must not be null");
Assert.state(savedUser.getFirstName().equals(testUser.getFirstName()),
"Saved user first name doesn't match");

firstNameUserFlux.collectList().block();

final Optional<User> optionalUserResult = repository.findById(testUser.getId()).blockOptional();
Assert.isTrue(optionalUserResult.isPresent(), "Cannot find user.");

final User result = optionalUserResult.get();
Assert.state(result.getFirstName().equals(testUser.getFirstName()),
"query result firstName doesn't match!");
Assert.state(result.getLastName().equals(testUser.getLastName()),
"query result lastName doesn't match!");

LOGGER.info("findOne in User collection get result: {}", result.getFirstName());
}

@PostConstruct
public void setup() {
// For this example, remove all of the existing records.
this.repository.deleteAll().block();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package sample.convert;

import org.springframework.data.annotation.Id;

import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey;

@Document(collection = "mycollection")
public class User {
@Id
private String id;

private String firstName;

@PartitionKey
private String lastName;

private String address;

public User() {}

public User(String id, String firstName, String lastName, String address) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
}

/**
* @return the id
*/
public String getId() {
return id;
}

/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}

/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}

/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}

/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}

/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}

/**
* @return the address
*/
public String getAddress() {
return address;
}

/**
* @param address the address to set
*/
public void setAddress(String address) {
this.address = address;
}

@Override
public String toString() {
return String.format("%s %s, %s", firstName, lastName, address);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package sample.convert;

import com.microsoft.azure.spring.data.cosmosdb.repository.ReactiveCosmosRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;

@Repository
public interface UserRepository extends ReactiveCosmosRepository<User, String> {

Flux<User> findByFirstName(String firstName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.cloud.azure.appconfiguration.stores[0].connection-string=${CONFIG_STORE_CONNECTION_STRING}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Release History

## 1.2.8-beta.1 (Unreleased)
Loading

0 comments on commit 6d0907b

Please sign in to comment.