This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from davidzhao98/upgrade_java_client
Upgrade java client
- Loading branch information
Showing
10 changed files
with
269 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2019 Nike, 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. | ||
*/ | ||
|
||
sourceSets { | ||
integration { | ||
java.srcDir file('src/integration/java') | ||
resources.srcDir file('src/integration/resources') | ||
} | ||
} | ||
|
||
task integration(type: Test, description: 'Runs integration tests') { | ||
testClassesDir = sourceSets.integration.output.classesDir | ||
classpath = sourceSets.integration.runtimeClasspath | ||
} | ||
|
||
dependencies { | ||
integrationCompile sourceSets.main.output | ||
integrationCompile configurations.testCompile | ||
integrationCompile sourceSets.test.output | ||
integrationCompile 'com.fieldju:commons:1.1.0' | ||
integrationCompile group: 'org.projectlombok', name: 'lombok', version: '1.18.8' | ||
integrationRuntime configurations.testRuntime | ||
} | ||
|
||
integration { | ||
testLogging { | ||
showStandardStreams = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,6 @@ | ||
# | ||
# Copyright (c) 2017 Nike, 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. | ||
# | ||
|
||
#Mon Aug 29 15:51:55 PDT 2016 | ||
#Thu Jun 06 14:24:12 PDT 2019 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip |
114 changes: 114 additions & 0 deletions
114
...tegration/java/com/nike/cerberus/springboot/CerberusSpringBootClientIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (c) 2019 Nike, 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 com.nike.cerberus.springboot; | ||
|
||
import com.fieldju.commons.EnvUtils; | ||
import com.nike.cerberus.client.CerberusClient; | ||
import com.nike.cerberus.client.CerberusServerException; | ||
import com.nike.cerberus.client.model.CerberusListResponse; | ||
import com.nike.cerberus.client.model.CerberusResponse; | ||
import com.nike.cerberus.springboot.testapp.IntegrationTestSpringApp; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.junit.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class CerberusSpringBootClientIntegrationTests { | ||
|
||
private IntegrationTestSpringApp app; | ||
|
||
private String cerberusRootSdbPath; | ||
private String secretPath; | ||
private String sdbFullSecretPath; | ||
private Map<String, String> secretData; | ||
private ExecutorService executorService = Executors.newSingleThreadExecutor(); | ||
|
||
@Before | ||
public void before() { | ||
EnvUtils.getRequiredEnv("CERBERUS_URL"); | ||
EnvUtils.getRequiredEnv("CERBERUS_REGION"); | ||
cerberusRootSdbPath = EnvUtils.getRequiredEnv("SDB_ROOT_PATH"); | ||
|
||
secretPath = UUID.randomUUID().toString(); | ||
sdbFullSecretPath = cerberusRootSdbPath + secretPath; | ||
|
||
String key = RandomStringUtils.randomAlphabetic(15); | ||
String value = RandomStringUtils.randomAlphabetic(25); | ||
secretData = new HashMap<>(); | ||
secretData.put(key, value); | ||
|
||
app = new IntegrationTestSpringApp(); | ||
|
||
executorService.submit(() -> app.run()); | ||
} | ||
|
||
@After | ||
public void after() { | ||
app.shutdown(); | ||
} | ||
|
||
@Test | ||
public void test_that_the_cerberus_springboot_client_can_be_used_in_a_spring_app() { | ||
CerberusClient cerberusClient = app.getApplicationContext().getBean(CerberusClient.class); | ||
|
||
// create secret | ||
cerberusClient.write(sdbFullSecretPath, secretData); | ||
|
||
// read secret | ||
CerberusResponse cerberusReadResponse = cerberusClient.read(sdbFullSecretPath); | ||
assertEquals(secretData, cerberusReadResponse.getData()); | ||
|
||
// list secrets | ||
CerberusListResponse cerberusListResponse = cerberusClient.list(cerberusRootSdbPath); | ||
assertTrue(cerberusListResponse.getKeys().contains(secretPath)); | ||
|
||
// update secret | ||
Map<String, String> newSecretData = generateNewSecretData(); | ||
cerberusClient.write(sdbFullSecretPath, newSecretData); | ||
secretData = newSecretData; | ||
|
||
// confirm updated secret data | ||
CerberusResponse cerberusReadResponseUpdated = cerberusClient.read(sdbFullSecretPath); | ||
assertEquals(newSecretData, cerberusReadResponseUpdated.getData()); | ||
|
||
// delete secret | ||
cerberusClient.delete(sdbFullSecretPath); | ||
|
||
// confirm secret is deleted | ||
try { | ||
cerberusClient.read(sdbFullSecretPath); | ||
} catch (CerberusServerException cse) { | ||
assertEquals(404, cse.getCode()); | ||
} | ||
} | ||
|
||
private Map<String, String> generateNewSecretData() { | ||
String key = RandomStringUtils.randomAlphabetic(20); | ||
String value = RandomStringUtils.randomAlphabetic(30); | ||
Map<String, String> newSecretData = new HashMap<>(); | ||
newSecretData.put(key, value); | ||
|
||
return newSecretData; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2019 Nike, 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 com.nike.cerberus.springboot.testapp; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
||
@Slf4j | ||
public class IntegrationTestSpringApp { | ||
|
||
private final ApplicationContext applicationContext; | ||
private boolean isRunning = true; | ||
|
||
public ApplicationContext getApplicationContext() { | ||
return applicationContext; | ||
} | ||
|
||
public void shutdown() { | ||
isRunning = false; | ||
} | ||
|
||
public void run() { | ||
while (isRunning) { | ||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException("Sleep interrupted"); | ||
} | ||
} | ||
} | ||
|
||
public IntegrationTestSpringApp() { | ||
applicationContext = new AnnotationConfigApplicationContext("com.nike.cerberus.springboot.testapp"); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringAppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2019 Nike, 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 com.nike.cerberus.springboot.testapp; | ||
|
||
import com.nike.cerberus.springboot.CerberusClientSpringBootConfiguration; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@Slf4j | ||
@Configuration | ||
@Import(CerberusClientSpringBootConfiguration.class) | ||
public class IntegrationTestSpringAppConfig { | ||
public IntegrationTestSpringAppConfig() { | ||
log.info("IntegrationTestSpringAppConfig Loaded"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters