Skip to content

Commit

Permalink
Merge branch 'dev_openapi_v2.0.0_major_rel' into okta-289659-add-even…
Browse files Browse the repository at this point in the history
…t-hooks-integration-tests
  • Loading branch information
arvindkrishnakumar-okta committed Jun 16, 2020
2 parents 988c11e + 8fbb76f commit 497d2d1
Show file tree
Hide file tree
Showing 14 changed files with 802 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class SessionsTest {

InternalDataStore dataStore = mock(InternalDataStore)

new DefaultUser(dataStore, [id: "test_user_id"]).endAllSessions()
new DefaultUser(dataStore, [id: "test_user_id"]).clearSessions()
verify(dataStore).delete("/api/v1/users/test_user_id/sessions", Collections.emptyMap(), Collections.emptyMap())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class ApplicationsIT extends ITSupport {
// issue: listApplicationUsers() occasionally throws HTTP 404, Okta E0000007 - Resource not found error.
// adding a sleep after createApplication() helps resolve the above issue.
sleep(2000)

AppUserList appUserList = app.listApplicationUsers()
assertThat appUserList.iterator().size(), equalTo(0)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Okta
* Copyright 2018-Present Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Okta
* Copyright 2018-Present Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import static com.okta.sdk.tests.it.util.Util.assertRoleAbsent
import static com.okta.sdk.tests.it.util.Util.validateGroup

/**
* Tests for /api/v1/groups/roles
* Tests for {@code /api/v1/groups/roles}.
* @since 2.0.0
*/
class GroupRolesIT extends ITSupport {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Okta
* Copyright 2018-Present Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,7 +39,7 @@ import static org.hamcrest.MatcherAssert.assertThat
import static org.hamcrest.Matchers.*

/**
* Tests for /api/v1/groups/rules
* Tests for {@code /api/v1/groups/rules}.
* @since 0.5.0
*/
class GroupRulesIT implements CrudTestSupport {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Okta
* Copyright 2018-Present Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,7 +32,7 @@ import static org.hamcrest.MatcherAssert.assertThat
import static org.hamcrest.Matchers.*

/**
* Tests for /api/v1/groups
* Tests for {@code /api/v1/groups}.
* @since 0.5.0
*/
class GroupsIT implements CrudTestSupport {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* Copyright 2020-Present Okta, 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.okta.sdk.tests.it

import com.okta.sdk.resource.linked.object.LinkedObject
import com.okta.sdk.resource.linked.object.LinkedObjectDetailsType
import com.okta.sdk.resource.linked.object.LinkedObjectDetails
import com.okta.sdk.tests.it.util.ITSupport
import org.testng.annotations.Test
import wiremock.org.apache.commons.lang3.RandomStringUtils

import static com.okta.sdk.tests.it.util.Util.assertLinkedObjectPresent
import static org.hamcrest.MatcherAssert.assertThat
import static org.hamcrest.Matchers.equalTo
import static org.hamcrest.Matchers.notNullValue

/**
* Tests for {@code /api/v1/meta/schemas/user/linkedObjects}.
* @since 2.0.0
*/
class LinkedObjectsIT extends ITSupport {

@Test
void addLinkedObjectDefinitionTest() {
String primaryName = "manager" + RandomStringUtils.randomAlphanumeric(25)
String associatedName = "subordinate" + RandomStringUtils.randomAlphanumeric(25)

LinkedObjectDetails primary = client.instantiate(LinkedObjectDetails)
.setName(primaryName)
.setTitle("Manager")
.setDescription("Manager link property")
.setType(LinkedObjectDetailsType.USER)

LinkedObjectDetails associated = client.instantiate(LinkedObjectDetails)
.setName(associatedName)
.setTitle("Subordinate")
.setDescription("Subordinate link property")
.setType(LinkedObjectDetailsType.USER)

LinkedObject linkedObject = client.instantiate(LinkedObject)
.setPrimary(primary)
.setAssociated(associated)
registerForCleanup(linkedObject)

LinkedObject createdLinkedObjectDefinition = client.addLinkedObjectDefinition(linkedObject)

assertThat(createdLinkedObjectDefinition.getPrimary(), notNullValue())
assertThat(createdLinkedObjectDefinition.getPrimary().getName(), equalTo(primaryName))
assertThat(createdLinkedObjectDefinition.getPrimary().getTitle(), equalTo("Manager"))
assertThat(createdLinkedObjectDefinition.getPrimary().getDescription(), equalTo("Manager link property"))
assertThat(createdLinkedObjectDefinition.getPrimary().getType(), equalTo(LinkedObjectDetailsType.USER))
assertThat(createdLinkedObjectDefinition.getAssociated(), notNullValue())
assertThat(createdLinkedObjectDefinition.getAssociated().getName(), equalTo(associatedName))
assertThat(createdLinkedObjectDefinition.getAssociated().getTitle(), equalTo("Subordinate"))
assertThat(createdLinkedObjectDefinition.getAssociated().getDescription(), equalTo("Subordinate link property"))
assertThat(createdLinkedObjectDefinition.getAssociated().getType(), equalTo(LinkedObjectDetailsType.USER))
}

@Test
void getLinkedObjectDefinitionByPrimaryNameTest() {
String primaryName = "manager" + RandomStringUtils.randomAlphanumeric(25)
String associatedName = "subordinate" + RandomStringUtils.randomAlphanumeric(25)

LinkedObjectDetails primary = client.instantiate(LinkedObjectDetails)
.setName(primaryName)
.setTitle("Primary")
.setDescription("Primary link property")
.setType(LinkedObjectDetailsType.USER)

LinkedObjectDetails associated = client.instantiate(LinkedObjectDetails)
.setName(associatedName)
.setTitle("Associated")
.setDescription("Associated link property")
.setType(LinkedObjectDetailsType.USER)

LinkedObject linkedObject = client.instantiate(LinkedObject)
.setPrimary(primary)
.setAssociated(associated)
registerForCleanup(linkedObject)

client.addLinkedObjectDefinition(linkedObject)

LinkedObject retrievedLinkedObject = client.getLinkedObjectDefinition(primaryName)

assertThat(retrievedLinkedObject.getPrimary(), notNullValue())
assertThat(retrievedLinkedObject.getPrimary().getName(), equalTo(primaryName))
assertThat(retrievedLinkedObject.getPrimary().getTitle(), equalTo("Primary"))
assertThat(retrievedLinkedObject.getPrimary().getDescription(), equalTo("Primary link property"))
assertThat(retrievedLinkedObject.getPrimary().getType(), equalTo(LinkedObjectDetailsType.USER))
assertThat(retrievedLinkedObject.getAssociated(), notNullValue())
assertThat(retrievedLinkedObject.getAssociated().getName(), equalTo(associatedName))
assertThat(retrievedLinkedObject.getAssociated().getTitle(), equalTo("Associated"))
assertThat(retrievedLinkedObject.getAssociated().getDescription(), equalTo("Associated link property"))
assertThat(retrievedLinkedObject.getAssociated().getType(), equalTo(LinkedObjectDetailsType.USER))
}

@Test
void getLinkedObjectDefinitionByAssociatedNameTest() {
String primaryName = "manager" + RandomStringUtils.randomAlphanumeric(25)
String associatedName = "subordinate" + RandomStringUtils.randomAlphanumeric(25)

LinkedObjectDetails primary = client.instantiate(LinkedObjectDetails)
.setName(primaryName)
.setTitle("Primary")
.setDescription("Primary link property")
.setType(LinkedObjectDetailsType.USER)

LinkedObjectDetails associated = client.instantiate(LinkedObjectDetails)
.setName(associatedName)
.setTitle("Associated")
.setDescription("Associated link property")
.setType(LinkedObjectDetailsType.USER)

LinkedObject linkedObject = client.instantiate(LinkedObject)
.setPrimary(primary)
.setAssociated(associated)
registerForCleanup(linkedObject)

client.addLinkedObjectDefinition(linkedObject)

LinkedObject retrievedLinkedObject = client.getLinkedObjectDefinition(associatedName)

assertThat(retrievedLinkedObject.getPrimary(), notNullValue())
assertThat(retrievedLinkedObject.getPrimary().getName(), equalTo(primaryName))
assertThat(retrievedLinkedObject.getPrimary().getTitle(), equalTo("Primary"))
assertThat(retrievedLinkedObject.getPrimary().getDescription(), equalTo("Primary link property"))
assertThat(retrievedLinkedObject.getPrimary().getType(), equalTo(LinkedObjectDetailsType.USER))
assertThat(retrievedLinkedObject.getAssociated(), notNullValue())
assertThat(retrievedLinkedObject.getAssociated().getName(), equalTo(associatedName))
assertThat(retrievedLinkedObject.getAssociated().getTitle(), equalTo("Associated"))
assertThat(retrievedLinkedObject.getAssociated().getDescription(), equalTo("Associated link property"))
assertThat(retrievedLinkedObject.getAssociated().getType(), equalTo(LinkedObjectDetailsType.USER))
}

@Test
void getAllLinkedObjectDefinitionsTest() {
// create first linked object definition

String primaryName1 = "manager" + RandomStringUtils.randomAlphanumeric(25)
String associatedName1 = "subordinate" + RandomStringUtils.randomAlphanumeric(25)

LinkedObjectDetails primary1 = client.instantiate(LinkedObjectDetails)
.setName(primaryName1)
.setTitle("Primary")
.setDescription("Primary link property")
.setType(LinkedObjectDetailsType.USER)

LinkedObjectDetails associated1 = client.instantiate(LinkedObjectDetails)
.setName(associatedName1)
.setTitle("Associated")
.setDescription("Associated link property")
.setType(LinkedObjectDetailsType.USER)

LinkedObject linkedObject1 = client.instantiate(LinkedObject)
.setPrimary(primary1)
.setAssociated(associated1)
registerForCleanup(linkedObject1)

LinkedObject createdLinkedObjectDefinition1 = client.addLinkedObjectDefinition(linkedObject1)

// create second linked object definition

String primaryName2 = "manager" + RandomStringUtils.randomAlphanumeric(25)
String associatedName2 = "subordinate" + RandomStringUtils.randomAlphanumeric(25)

LinkedObjectDetails primary2 = client.instantiate(LinkedObjectDetails)
.setName(primaryName2)
.setTitle("Primary")
.setDescription("Primary link property")
.setType(LinkedObjectDetailsType.USER)

LinkedObjectDetails associated2 = client.instantiate(LinkedObjectDetails)
.setName(associatedName2)
.setTitle("Associated")
.setDescription("Associated link property")
.setType(LinkedObjectDetailsType.USER)

LinkedObject linkedObject2 = client.instantiate(LinkedObject)
.setPrimary(primary2)
.setAssociated(associated2)
registerForCleanup(linkedObject2)

LinkedObject createdLinkedObjectDefinition2 = client.addLinkedObjectDefinition(linkedObject2)

assertLinkedObjectPresent(client.listLinkedObjectDefinitions(), createdLinkedObjectDefinition1)
assertLinkedObjectPresent(client.listLinkedObjectDefinitions(), createdLinkedObjectDefinition2)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright 2020-Present Okta, 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.okta.sdk.tests.it

import com.okta.sdk.resource.template.SmsTemplateTranslations
import com.okta.sdk.resource.template.SmsTemplate
import com.okta.sdk.resource.template.SmsTemplateType
import com.okta.sdk.tests.it.util.ITSupport
import org.testng.annotations.Test

import static com.okta.sdk.tests.it.util.Util.assertPresent
import static com.okta.sdk.tests.it.util.Util.assertNotPresent
import static org.hamcrest.MatcherAssert.assertThat
import static org.hamcrest.Matchers.*

/**
* Tests for {@code /api/v1/templates/sms}.
* @since 2.0.0
*/
class SmsTemplateIT extends ITSupport {

@Test
void customTemplatesCrudTest() {
def templateName = "template-" + UUID.randomUUID().toString()

// create translations
SmsTemplateTranslations smsTemplateTranslations = client.instantiate(SmsTemplateTranslations)
smsTemplateTranslations.put("de", "\${org.name}: ihre bestätigungscode ist \${code}")
smsTemplateTranslations.put("it", "\${org.name}: il codice di verifica è \${code}")

// create template
SmsTemplate smsTemplate = client.createSmsTemplate(client.instantiate(SmsTemplate)
.setName(templateName)
.setType(SmsTemplateType.CODE)
.setTemplate("\${org.name}: your verification code is \${code}")
.setTranslations(smsTemplateTranslations))
registerForCleanup(smsTemplate)

assertThat(smsTemplate.getId(), notNullValue())

// list templates
assertPresent(client.listSmsTemplates(), smsTemplate)

// retrieve template
SmsTemplate retrievedSmsTemplate = client.getSmsTemplate(smsTemplate.getId())
assertThat(retrievedSmsTemplate, notNullValue())
assertThat(retrievedSmsTemplate.getTranslations().keySet(), hasSize(2))

// partial update template with 1 empty translation
SmsTemplateTranslations partialUpdateTranslations = client.instantiate(SmsTemplateTranslations)
partialUpdateTranslations.put("de", "") // supplying empty value here so it gets removed by partial update operation (by design)

smsTemplate.setTranslations(partialUpdateTranslations)

smsTemplate.partialUpdate()
assertThat(smsTemplate.getTranslations().keySet(), hasSize(1))

// partial update again with 2 new translations
smsTemplate.getTranslations().put("es", "\${org.name}: su código de inscripción es \${code}")
smsTemplate.getTranslations().put("fr", "\${org.name}: votre code d'inscription est \${code}",)

smsTemplate.partialUpdate()
assertThat(smsTemplate.getTranslations().keySet(), hasSize(3))

// full update template
SmsTemplateTranslations fullUpdateTranslations = client.instantiate(SmsTemplateTranslations)
fullUpdateTranslations.put("de", "\${org.name}: Hier ist Ihr Registrierungscode: \${code}")

smsTemplate.setName("new-" + templateName)
smsTemplate.setType(SmsTemplateType.CODE)
smsTemplate.setTemplate("\${org.name}: Here is your enrollment code: \${code}")
smsTemplate.setTranslations(fullUpdateTranslations)

smsTemplate.update()
assertThat(smsTemplate.getName(), is("new-" + templateName))
assertThat(smsTemplate.getTranslations().keySet(), hasSize(1))

// list templates
assertPresent(client.listSmsTemplates(), smsTemplate)

// delete template
smsTemplate.delete()
assertNotPresent(client.listSmsTemplates(), smsTemplate)
}
}
Loading

0 comments on commit 497d2d1

Please sign in to comment.