Skip to content

Commit

Permalink
fix(SDK): IBM Cloud SCC Java SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav Goswami committed Jun 1, 2021
1 parent 02f141b commit 0bfe060
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 55 deletions.
18 changes: 7 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ env:
- MVN_ARGS="--settings build/.travis.settings.xml"

stages:
- name: Build & Test
- name: Release & Deployment
- name: Verify
- name: Release
if: branch = main AND type = push AND fork = false

before_install:
Expand All @@ -32,20 +32,16 @@ before_install:

jobs:
include:
- stage: Build & Test
- stage: Verify
install:
- curl -s https://codecov.io/bash > $HOME/codecov-bash.sh && chmod +x $HOME/codecov-bash.sh
script:
- curl https://us-south.functions.appdomain.cloud/api/v1/web/e6b54af6-ab44-4149-a8e4-e906dcc58136/default/secadvstg-location-shift.json
- echo "${FINDINGS_ENV}" | base64 -d >> findings_v1.env
- echo "${NOTIFICATIONS_ENV}" | base64 -d >> notifications_v1.env
# - echo "${CONFIGURATION_GOVERNANCE_ENV}" | base64 -d >> configuration_governance_v1.env
- mvn verify -fae -DskipITs $MVN_ARGS
- mvn verify -fae -DskipITs $MVN_ARGS
after_success:
- build/publishCodeCoverage.sh

- stage: Release & Deployment
name: Release & Deployment
- stage: Release
name: Release
jdk: openjdk8
install:
- sudo apt-get update
Expand All @@ -58,7 +54,7 @@ jobs:
- npm install @semantic-release/git
- npm install @semantic-release/github
script:
- mvn clean verify
- build/testScript.sh
- npx semantic-release
- mvn deploy $MVN_ARGS -DskipITs -P central
deploy:
Expand Down
11 changes: 11 additions & 0 deletions build/testScript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -euo pipefail

if [[ $TRAVIS_BRANCH == "main" && $TRAVIS_PULL_REQUEST == "false" ]]; then
curl https://us-south.functions.appdomain.cloud/api/v1/web/e6b54af6-ab44-4149-a8e4-e906dcc58136/default/secadvstg-location-shift.json
echo "${FINDINGS_ENV}" | base64 -d >> findings_v1.env
echo "${NOTIFICATIONS_ENV}" | base64 -d >> notifications_v1.env
# echo "${CONFIGURATION_GOVERNANCE_ENV}" | base64 -d >> configuration_governance_v1.env
mvn clean verify
fi
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import static org.testng.Assert.fail;

import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;

import com.ibm.cloud.scc.findings.v1.model.ApiListNoteOccurrencesResponse;
import com.ibm.cloud.scc.findings.v1.model.ApiListNotesResponse;
Expand Down Expand Up @@ -89,6 +91,7 @@ public class FindingsIT extends SdkIntegrationTestBase {
final String accountID = System.getenv("ACCOUNT_ID");
String providerID = System.getenv("PROVIDER_ID");
final String testString = "testString";
String identifier = System.getenv("TRAVIS_BUILD_NUMBER");

public String getConfigFilename() {
return "../../findings_v1.env";
Expand All @@ -97,6 +100,10 @@ public String getConfigFilename() {
@BeforeClass
public void constructService() {

if(identifier == null){
identifier = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
}

if(providerID == null){
providerID = "sdk-it";
}
Expand Down Expand Up @@ -169,7 +176,7 @@ public void testCreateNoteFinding() throws Exception {
.shortDescription(testString)
.longDescription(testString)
.kind("FINDING")
.id("finding-note")
.id(String.format("finding-note-%s", identifier))
.reportedBy(reporterModel)
.relatedUrl(new java.util.ArrayList<ApiNoteRelatedUrl>(java.util.Arrays.asList(apiNoteRelatedUrlModel)))
.expirationTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z"))
Expand Down Expand Up @@ -211,7 +218,7 @@ public void testCreateNoteKpi() throws Exception {
.shortDescription(testString)
.longDescription(testString)
.kind("KPI")
.id("kpi-note")
.id(String.format("kpi-note-%s", identifier))
.reportedBy(reporterModel)
.expirationTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z"))
.shared(true)
Expand Down Expand Up @@ -260,7 +267,7 @@ public void testCreateNoteCard() throws Exception {
.section(testString)
.title(testString)
.subtitle(testString)
.findingNoteNames(new java.util.ArrayList<String>(java.util.Arrays.asList(testString)))
.findingNoteNames(new java.util.ArrayList<String>(java.util.Arrays.asList(String.format("%s/providers/%s/notes/finding-note-%s", accountID, providerID, identifier))))
.requiresConfiguration(true)
.badgeText(testString)
.badgeImage(testString)
Expand All @@ -273,7 +280,7 @@ public void testCreateNoteCard() throws Exception {
.shortDescription(testString)
.longDescription(testString)
.kind("CARD")
.id("card-note")
.id(String.format("card-note-%s", identifier))
.reportedBy(reporterModel)
.expirationTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z"))
.shared(true)
Expand Down Expand Up @@ -315,7 +322,7 @@ public void testCreateNoteSection() throws Exception {
.shortDescription(testString)
.longDescription(testString)
.kind("SECTION")
.id("section-note")
.id(String.format("section-note-%s", identifier))
.reportedBy(reporterModel)
.expirationTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z"))
.shared(true)
Expand Down Expand Up @@ -366,7 +373,7 @@ public void testGetNote() throws Exception {
GetNoteOptions getNoteOptions = new GetNoteOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.noteId("kpi-note")
.noteId(String.format("kpi-note-%s", identifier))
.build();

// Invoke operation
Expand Down Expand Up @@ -411,11 +418,11 @@ public void testUpdateNoteFinding() throws Exception {
UpdateNoteOptions updateNoteOptions = new UpdateNoteOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.noteId("finding-note")
.noteId(String.format("finding-note-%s", identifier))
.shortDescription(testString)
.longDescription(testString)
.kind("FINDING")
.id("finding-note")
.id(String.format("finding-note-%s", identifier))
.reportedBy(reporterModel)
.relatedUrl(new java.util.ArrayList<ApiNoteRelatedUrl>(java.util.Arrays.asList(apiNoteRelatedUrlModel)))
.expirationTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z"))
Expand Down Expand Up @@ -454,11 +461,11 @@ public void testUpdateNoteKpi() throws Exception {
UpdateNoteOptions updateNoteOptions = new UpdateNoteOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.noteId("kpi-note")
.noteId(String.format("kpi-note-%s", identifier))
.shortDescription(testString)
.longDescription(testString)
.kind("KPI")
.id("kpi-note")
.id(String.format("kpi-note-%s", identifier))
.reportedBy(reporterModel)
.expirationTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z"))
.shared(true)
Expand Down Expand Up @@ -517,11 +524,11 @@ public void testUpdateNoteCard() throws Exception {
UpdateNoteOptions updateNoteOptions = new UpdateNoteOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.noteId("card-note")
.noteId(String.format("card-note-%s", identifier))
.shortDescription(testString)
.longDescription(testString)
.kind("CARD")
.id("card-note")
.id(String.format("card-note-%s", identifier))
.reportedBy(reporterModel)
.expirationTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z"))
.shared(true)
Expand Down Expand Up @@ -560,11 +567,11 @@ public void testUpdateNoteSection() throws Exception {
UpdateNoteOptions updateNoteOptions = new UpdateNoteOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.noteId("section-note")
.noteId(String.format("section-note-%s", identifier))
.shortDescription(testString)
.longDescription(testString)
.kind("SECTION")
.id("section-note")
.id(String.format("section-note-%s", identifier))
.reportedBy(reporterModel)
.expirationTime(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z"))
.shared(true)
Expand Down Expand Up @@ -637,9 +644,9 @@ public void testCreateOccurrenceFinding() throws Exception {
CreateOccurrenceOptions createOccurrenceOptions = new CreateOccurrenceOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.noteName(String.format("%s/providers/%s/notes/%s", accountID, providerID, "finding-note"))
.noteName(String.format("%s/providers/%s/notes/finding-note-%s", accountID, providerID, identifier))
.kind("FINDING")
.id("finding-occurrence")
.id(String.format("finding-occurrence-%s", identifier))
.resourceUrl(testString)
.remediation(testString)
.context(contextModel)
Expand Down Expand Up @@ -686,9 +693,9 @@ public void testCreateOccurrenceKpi() throws Exception {
CreateOccurrenceOptions createOccurrenceOptions = new CreateOccurrenceOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.noteName(String.format("%s/providers/%s/notes/%s", accountID, providerID, "kpi-note"))
.noteName(String.format("%s/providers/%s/notes/kpi-note-%s", accountID, providerID, identifier))
.kind("KPI")
.id("kpi-occurrence")
.id(String.format("kpi-occurrence-%s", identifier))
.resourceUrl(testString)
.remediation(testString)
.context(contextModel)
Expand Down Expand Up @@ -717,7 +724,7 @@ public void testGetOccurrenceNote() throws Exception {
GetOccurrenceNoteOptions getOccurrenceNoteOptions = new GetOccurrenceNoteOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.occurrenceId("finding-occurrence")
.occurrenceId(String.format("kpi-occurrence-%s", identifier))
.build();

// Invoke operation
Expand Down Expand Up @@ -764,7 +771,7 @@ public void testListNoteOccurrences() throws Exception {
ListNoteOccurrencesOptions listNoteOccurrencesOptions = new ListNoteOccurrencesOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.noteId("finding-note")
.noteId(String.format("kpi-note-%s", identifier))
.build();

// Invoke operation
Expand All @@ -788,7 +795,7 @@ public void testGetOccurrence() throws Exception {
GetOccurrenceOptions getOccurrenceOptions = new GetOccurrenceOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.occurrenceId("finding-occurrence")
.occurrenceId(String.format("kpi-occurrence-%s", identifier))
.build();

// Invoke operation
Expand Down Expand Up @@ -857,10 +864,10 @@ public void testUpdateOccurrenceFinding() throws Exception {
UpdateOccurrenceOptions updateOccurrenceOptions = new UpdateOccurrenceOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.occurrenceId("finding-occurrence")
.noteName(String.format("%s/providers/%s/notes/%s", accountID, providerID, "finding-note"))
.occurrenceId(String.format("finding-occurrence-%s", identifier))
.noteName(String.format("%s/providers/%s/notes/finding-note-%s", accountID, providerID, identifier))
.kind("FINDING")
.id("finding-occurrence")
.id(String.format("finding-occurrence-%s", identifier))
.resourceUrl(testString)
.remediation(testString)
.context(contextModel)
Expand Down Expand Up @@ -906,10 +913,10 @@ public void testUpdateOccurrenceKpi() throws Exception {
UpdateOccurrenceOptions updateOccurrenceOptions = new UpdateOccurrenceOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.occurrenceId("kpi-occurrence")
.noteName(String.format("%s/providers/%s/notes/%s", accountID, providerID, "kpi-note"))
.occurrenceId(String.format("kpi-occurrence-%s", identifier))
.noteName(String.format("%s/providers/%s/notes/kpi-note-%s", accountID, providerID, identifier))
.kind("KPI")
.id("kpi-occurrence")
.id(String.format("kpi-occurrence-%s", identifier))
.resourceUrl(testString)
.remediation(testString)
.context(contextModel)
Expand Down Expand Up @@ -959,7 +966,7 @@ public void testDeleteOccurrence() throws Exception {
DeleteOccurrenceOptions deleteOccurrenceOptions = new DeleteOccurrenceOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.occurrenceId("kpi-occurrence")
.occurrenceId(String.format("kpi-occurrence-%s", identifier))
.build();

// Invoke operation
Expand All @@ -979,7 +986,7 @@ public void testDeleteNote() throws Exception {
DeleteNoteOptions deleteNoteOptions = new DeleteNoteOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.noteId("kpi-note")
.noteId(String.format("kpi-note-%s", identifier))
.build();

// Invoke operation
Expand Down Expand Up @@ -1007,12 +1014,15 @@ public void tearDown() {
.build();
Response<ApiListNotesResponse> notes = service.listNotes(listNotesOptions).execute();
for(ApiNote note: notes.getResult().getNotes()){
DeleteNoteOptions deleteNoteOptions = new DeleteNoteOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.noteId(note.id())
.build();
service.deleteNote(deleteNoteOptions).execute();
String[] parts = note.id().split("-");
if(parts[parts.length-1]==identifier){
DeleteNoteOptions deleteNoteOptions = new DeleteNoteOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.noteId(note.id())
.build();
service.deleteNote(deleteNoteOptions).execute();
}
}

ListOccurrencesOptions listOccurrencesOptions = new ListOccurrencesOptions.Builder()
Expand All @@ -1021,12 +1031,15 @@ public void tearDown() {
.build();
Response<ApiListOccurrencesResponse> occurrences = service.listOccurrences(listOccurrencesOptions).execute();
for(ApiOccurrence occurrence: occurrences.getResult().getOccurrences()){
DeleteOccurrenceOptions deleteOccurrenceOptions = new DeleteOccurrenceOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.occurrenceId(occurrence.id())
.build();
service.deleteOccurrence(deleteOccurrenceOptions).execute();
String[] parts = occurrence.id().split("-");
if(parts[parts.length-1]==identifier){
DeleteOccurrenceOptions deleteOccurrenceOptions = new DeleteOccurrenceOptions.Builder()
.accountId(accountID)
.providerId(providerID)
.occurrenceId(occurrence.id())
.build();
service.deleteOccurrence(deleteOccurrenceOptions).execute();
}
}
System.out.println("cleanup was successful");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;

import com.ibm.cloud.scc.notifications.v1.model.Channel;
import com.ibm.cloud.scc.notifications.v1.model.ChannelDelete;
Expand Down Expand Up @@ -67,13 +69,19 @@ public class NotificationsIT extends SdkIntegrationTestBase {
final String accountID = System.getenv("ACCOUNT_ID");
String channelID = "";
final String testString = "testString";
String identifier = System.getenv("TRAVIS_BUILD_NUMBER");

public String getConfigFilename() {
return "../../notifications_v1.env";
}

@BeforeClass
public void constructService() {

if(identifier == null){
identifier = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
}

// Ask super if we should skip the tests.
if (skipTests()) {
return;
Expand Down Expand Up @@ -124,7 +132,7 @@ public void testCreateNotificationChannel() throws Exception {

CreateNotificationChannelOptions createNotificationChannelOptions = new CreateNotificationChannelOptions.Builder()
.accountId(accountID)
.name(testString)
.name(String.format("%s-%s", testString, identifier))
.type("Webhook")
.endpoint("https://webhook.site/136fe1e2-3c3f-4bff-925f-391fbb202546")
.description(testString)
Expand Down Expand Up @@ -183,7 +191,7 @@ public void testUpdateNotificationChannel() throws Exception {
UpdateNotificationChannelOptions updateNotificationChannelOptions = new UpdateNotificationChannelOptions.Builder()
.accountId(accountID)
.channelId(channelID)
.name(testString)
.name(String.format("%s-%s", testString, identifier))
.type("Webhook")
.endpoint("https://webhook.site/136fe1e2-3c3f-4bff-925f-391fbb202546")
.description(testString)
Expand Down Expand Up @@ -285,7 +293,7 @@ public void testDeleteNotificationChannels() throws Exception {

CreateNotificationChannelOptions createNotificationChannelOptions = new CreateNotificationChannelOptions.Builder()
.accountId(accountID)
.name(testString)
.name(String.format("%s-%s", testString, identifier))
.type("Webhook")
.endpoint("https://webhook.site/136fe1e2-3c3f-4bff-925f-391fbb202546")
.description(testString)
Expand Down

0 comments on commit 0bfe060

Please sign in to comment.