-
Notifications
You must be signed in to change notification settings - Fork 136
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
OKTA-289659: Add Event Hooks Integration Tests #399
Merged
arvindkrishnakumar-okta
merged 15 commits into
dev_openapi_v2.0.0_major_rel
from
okta-289659-add-event-hooks-integration-tests
Jun 17, 2020
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
121f894
OKTA-289659: Add Event Hooks Integration Tests
arvindkrishnakumar-okta 988c11e
Merge branch 'dev_openapi_v2.0.0_major_rel' into okta-289659-add-even…
arvindkrishnakumar-okta 497d2d1
Merge branch 'dev_openapi_v2.0.0_major_rel' into okta-289659-add-even…
arvindkrishnakumar-okta 6d8456f
address some review comments
arvindkrishnakumar-okta 7a8bb6f
addressed review comments
arvindkrishnakumar-okta 76c5050
addressed review comments
arvindkrishnakumar-okta 85c50d7
addressed review comments
arvindkrishnakumar-okta 9492844
addressed review comments
arvindkrishnakumar-okta b3e87de
added license header to EventHookBuilder
arvindkrishnakumar-okta 0907206
addressed review comments
arvindkrishnakumar-okta 5deba2f
addressed review comments
arvindkrishnakumar-okta 39128ab
addressed review comments
arvindkrishnakumar-okta 08c4ede
minor refactor
arvindkrishnakumar-okta 7478d82
Merge branch 'dev_openapi_v2.0.0_major_rel' of https://github.com/okt…
arvindkrishnakumar-okta e7e519e
review comments addressed
arvindkrishnakumar-okta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
api/src/main/java/com/okta/sdk/resource/event/hook/EventHookBuilder.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,35 @@ | ||
/* | ||
* 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.resource.event.hook; | ||
|
||
import com.okta.commons.lang.Classes; | ||
import com.okta.sdk.client.Client; | ||
|
||
public interface EventHookBuilder { | ||
EventHookBuilder setName(String name); | ||
|
||
EventHookBuilder setUrl(String url); | ||
|
||
EventHookBuilder setAuthorizationHeaderValue(String authorizationHeaderValue); | ||
|
||
EventHookBuilder addHeader(String name, String value); | ||
|
||
EventHook buildAndCreate(Client client); | ||
|
||
static EventHookBuilder instance() { | ||
return Classes.newInstance("com.okta.sdk.impl.resource.event.hook.DefaultEventHookBuilder"); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
impl/src/main/java/com/okta/sdk/impl/resource/event/hook/DefaultEventHookBuilder.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,115 @@ | ||
/* | ||
* 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.impl.resource.event.hook; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Maps; | ||
import com.google.common.net.HttpHeaders; | ||
|
||
import com.okta.sdk.client.Client; | ||
import com.okta.sdk.resource.event.hook.EventHook; | ||
import com.okta.sdk.resource.event.hook.EventHookBuilder; | ||
import com.okta.sdk.resource.event.hook.EventHookChannel; | ||
import com.okta.sdk.resource.event.hook.EventHookChannelConfig; | ||
import com.okta.sdk.resource.event.hook.EventHookChannelConfigHeader; | ||
import com.okta.sdk.resource.event.hook.EventHookChannelConfigAuthScheme; | ||
import com.okta.sdk.resource.event.hook.EventHookChannelConfigAuthSchemeType; | ||
import com.okta.sdk.resource.event.hook.EventSubscriptions; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Builder for {@link EventHook}. | ||
* @since 2.0.0 | ||
*/ | ||
public class DefaultEventHookBuilder implements EventHookBuilder { | ||
|
||
private static final String LIFECYCLE_EVENT_CREATE = "user.lifecycle.create"; | ||
private static final String LIFECYCLE_EVENT_ACTIVATE = "user.lifecycle.activate"; | ||
|
||
private static final String VERSION = "1.0.0"; | ||
|
||
private String name; | ||
private String url; | ||
private String authorizationHeaderValue; | ||
private Map<String, String> headerMap = Maps.newHashMap(); | ||
|
||
@Override | ||
public EventHookBuilder setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
@Override | ||
public EventHookBuilder setUrl(String url) { | ||
this.url = url; | ||
return this; | ||
} | ||
|
||
@Override | ||
public EventHookBuilder setAuthorizationHeaderValue(String authorizationHeaderValue) { | ||
this.authorizationHeaderValue = authorizationHeaderValue; | ||
return this; | ||
} | ||
|
||
@Override | ||
public EventHookBuilder addHeader(String name, String value) { | ||
headerMap.put(name, value); | ||
return this; | ||
} | ||
|
||
@Override | ||
public EventHook buildAndCreate(Client client) { | ||
|
||
EventSubscriptions eventSubscriptions = client.instantiate(EventSubscriptions.class) | ||
.setType(EventSubscriptions.TypeEnum.EVENT_TYPE) | ||
.setItems(Arrays.asList(LIFECYCLE_EVENT_CREATE, LIFECYCLE_EVENT_ACTIVATE)); | ||
|
||
EventHookChannelConfigAuthScheme eventHookChannelConfigAuthScheme = | ||
client.instantiate(EventHookChannelConfigAuthScheme.class) | ||
.setType(EventHookChannelConfigAuthSchemeType.HEADER) | ||
.setKey(HttpHeaders.AUTHORIZATION) | ||
.setValue(authorizationHeaderValue); | ||
|
||
List<EventHookChannelConfigHeader> headers = Lists.newArrayList(); | ||
|
||
for (Map.Entry<String, String> entry : headerMap.entrySet()) { | ||
headers.add(client.instantiate(EventHookChannelConfigHeader.class) | ||
.setKey(entry.getKey()) | ||
.setValue(entry.getValue())); | ||
} | ||
|
||
EventHookChannelConfig eventHookChannelConfig = client.instantiate(EventHookChannelConfig.class) | ||
.setUri(url) | ||
.setHeaders(headers) | ||
.setAuthScheme(eventHookChannelConfigAuthScheme); | ||
|
||
EventHookChannel eventHookChannel = client.instantiate(EventHookChannel.class) | ||
.setType(EventHookChannel.TypeEnum.HTTP) | ||
.setVersion(VERSION) | ||
.setConfig(eventHookChannelConfig); | ||
|
||
EventHook createdEventHook = client.createEventHook(client.instantiate(EventHook.class) | ||
.setName(name) | ||
.setEvents(eventSubscriptions) | ||
.setChannel(eventHookChannel)); | ||
|
||
return createdEventHook; | ||
} | ||
|
||
} |
190 changes: 190 additions & 0 deletions
190
integration-tests/src/test/groovy/com/okta/sdk/tests/it/EventHooksIT.groovy
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,190 @@ | ||
/* | ||
* 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.ResourceException | ||
import com.okta.sdk.resource.event.hook.EventHook | ||
import com.okta.sdk.resource.event.hook.EventHookBuilder | ||
import com.okta.sdk.resource.event.hook.EventHookChannelConfigAuthScheme | ||
import com.okta.sdk.resource.event.hook.EventHookChannelConfigAuthSchemeType | ||
|
||
import com.okta.sdk.tests.it.util.ITSupport | ||
|
||
import org.testng.annotations.Test | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat | ||
import static org.hamcrest.Matchers.equalTo | ||
import static org.hamcrest.Matchers.iterableWithSize | ||
import static org.hamcrest.Matchers.notNullValue | ||
|
||
import static com.okta.sdk.tests.it.util.Util.assertPresent | ||
|
||
/** | ||
* Tests for {@code /api/v1/eventHooks}. | ||
* @since 2.0.0 | ||
*/ | ||
class EventHooksIT extends ITSupport { | ||
|
||
@Test | ||
void createEventHookTest() { | ||
String name = "event-hook-java-sdk-${UUID.randomUUID().toString()}" | ||
|
||
EventHook createdEventHook = EventHookBuilder.instance() | ||
.setName(name) | ||
.setUrl("https://www.example.com/eventHooks") | ||
.setAuthorizationHeaderValue("Test-Api-Key") | ||
.addHeader("X-Test-Header", "Test header value") | ||
.buildAndCreate(client); | ||
registerForCleanup(createdEventHook) | ||
|
||
assertThat(createdEventHook.getId(), notNullValue()) | ||
assertThat(createdEventHook.getName(), equalTo(name)) | ||
assertThat(createdEventHook.getStatus(), equalTo(EventHook.StatusEnum.ACTIVE)) | ||
assertThat(createdEventHook.getEvents().getItems(), iterableWithSize(2)) | ||
assertThat(createdEventHook.getChannel().getConfig().getUri(), equalTo("https://www.example.com/eventHooks")) | ||
|
||
createdEventHook.deactivate() | ||
} | ||
|
||
@Test | ||
void getEventHookTest() { | ||
String name = "event-hook-java-sdk-${UUID.randomUUID().toString()}" | ||
|
||
EventHook createdEventHook = EventHookBuilder.instance() | ||
.setName(name) | ||
.setUrl("https://www.example.com/eventHooks") | ||
.setAuthorizationHeaderValue("Test-Api-Key") | ||
.addHeader("X-Test-Header", "Test header value") | ||
.buildAndCreate(client); | ||
registerForCleanup(createdEventHook) | ||
|
||
assertThat(createdEventHook.getId(), notNullValue()) | ||
|
||
EventHook retrievedEventHook = client.getEventHook(createdEventHook.getId()) | ||
|
||
assertThat(retrievedEventHook.getId(), notNullValue()) | ||
assertThat(retrievedEventHook.getName(), equalTo(name)) | ||
assertThat(createdEventHook.getStatus(), equalTo(EventHook.StatusEnum.ACTIVE)) | ||
assertThat(retrievedEventHook.getEvents().getItems(), iterableWithSize(2)) | ||
assertThat(retrievedEventHook.getChannel().getConfig().getUri(), equalTo("https://www.example.com/eventHooks")) | ||
|
||
createdEventHook.deactivate() | ||
} | ||
|
||
@Test | ||
void updateEventHookTest() { | ||
String name = "event-hook-java-sdk-${UUID.randomUUID().toString()}" | ||
|
||
EventHook createdEventHook = EventHookBuilder.instance() | ||
.setName(name) | ||
.setUrl("https://www.example.com/eventHooks") | ||
.setAuthorizationHeaderValue("Test-Api-Key") | ||
.addHeader("X-Test-Header", "Test header value") | ||
.buildAndCreate(client); | ||
registerForCleanup(createdEventHook) | ||
|
||
assertThat(createdEventHook.getId(), notNullValue()) | ||
|
||
EventHook toBeUpdatedEventHook = createdEventHook.setName("updated-" + name) | ||
createdEventHook.getEvents().getItems().add("user.lifecycle.deactivate") | ||
createdEventHook.getChannel().getConfig().setAuthScheme(client.instantiate(EventHookChannelConfigAuthScheme) | ||
.setType(EventHookChannelConfigAuthSchemeType.HEADER) | ||
.setKey("Authorization") | ||
.setValue("Test-Api-Key-Updated")) | ||
.setUri("https://www.example.com/eventHooksUpdated") | ||
|
||
EventHook updatedEventHook = toBeUpdatedEventHook.update() | ||
|
||
assertThat(updatedEventHook.getId(), notNullValue()) | ||
assertThat(updatedEventHook.getId(), equalTo(createdEventHook.getId())) | ||
assertThat(createdEventHook.getStatus(), equalTo(EventHook.StatusEnum.ACTIVE)) | ||
assertThat(updatedEventHook.getName(), equalTo("updated-" + name)) | ||
assertThat(updatedEventHook.getEvents().getItems(), iterableWithSize(3)) | ||
assertThat(updatedEventHook.getChannel().getConfig().getUri(), equalTo("https://www.example.com/eventHooksUpdated")) | ||
|
||
createdEventHook.deactivate() | ||
} | ||
|
||
@Test | ||
void deleteEventHookTest() { | ||
String name = "event-hook-java-sdk-${UUID.randomUUID().toString()}" | ||
|
||
EventHook createdEventHook = EventHookBuilder.instance() | ||
.setName(name) | ||
.setUrl("https://www.example.com/eventHooks") | ||
.setAuthorizationHeaderValue("Test-Api-Key") | ||
.addHeader("X-Test-Header", "Test header value") | ||
.buildAndCreate(client); | ||
registerForCleanup(createdEventHook) | ||
|
||
assertThat(createdEventHook.getId(), notNullValue()) | ||
|
||
EventHook retrievedEventHook = client.getEventHook(createdEventHook.getId()) | ||
assertThat(retrievedEventHook.getId(), equalTo(createdEventHook.getId())) | ||
assertThat(retrievedEventHook.getStatus(), equalTo(EventHook.StatusEnum.ACTIVE)) | ||
|
||
createdEventHook.deactivate() | ||
createdEventHook.delete() | ||
|
||
try { | ||
client.getEventHook(createdEventHook.getId()) | ||
} | ||
catch (ResourceException e) { | ||
assertThat(e.status, equalTo(404)) | ||
} | ||
} | ||
|
||
@Test | ||
void listAllEventHooksTest() { | ||
String name = "event-hook-java-sdk-${UUID.randomUUID().toString()}" | ||
|
||
EventHook createdEventHook = EventHookBuilder.instance() | ||
.setName(name) | ||
.setUrl("https://www.example.com/eventHooks") | ||
.setAuthorizationHeaderValue("Test-Api-Key") | ||
.addHeader("X-Test-Header", "Test header value") | ||
.buildAndCreate(client); | ||
registerForCleanup(createdEventHook) | ||
|
||
assertThat(createdEventHook.getId(), notNullValue()) | ||
|
||
assertPresent(client.listEventHooks(), createdEventHook) | ||
|
||
createdEventHook.deactivate() | ||
} | ||
|
||
@Test | ||
void activateDeactivateEventHookTest() { | ||
String name = "event-hook-java-sdk-${UUID.randomUUID().toString()}" | ||
|
||
EventHook createdEventHook = EventHookBuilder.instance() | ||
.setName(name) | ||
.setUrl("https://www.example.com/eventHooks") | ||
.setAuthorizationHeaderValue("Test-Api-Key") | ||
.addHeader("X-Test-Header", "Test header value") | ||
.buildAndCreate(client); | ||
registerForCleanup(createdEventHook) | ||
|
||
assertThat(createdEventHook.getId(), notNullValue()) | ||
assertThat(createdEventHook.getStatus(), equalTo(EventHook.StatusEnum.ACTIVE)) | ||
|
||
createdEventHook.deactivate() | ||
|
||
EventHook retrievedEventHook = client.getEventHook(createdEventHook.getId()) | ||
|
||
assertThat(retrievedEventHook.getStatus(), equalTo(EventHook.StatusEnum.INACTIVE)) | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user.type seems a bit redundant, maybe just tag it with
user
?(maybe there are a bunch of other user type objects 🤷)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed :)
UserType
andUserTypeList
are the only classes in packagecom.okta.sdk.resource.user.type
.Will consider moving it to a different package (say
com.okta.sdk.resource.user
) as theuser.type
seems redundant. Will do this as part of separate PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://oktainc.atlassian.net/browse/OKTA-305898 created to address this improvement.