Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
Signed-off-by: SimoneFiorani <[email protected]>
  • Loading branch information
sfiorani authored and salvatore-coppola committed Dec 12, 2023
1 parent 2971f7c commit bf89c81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.kura.internal.rest.identity.provider.test;

import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;
Expand All @@ -27,6 +28,7 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.eclipse.kura.KuraErrorCode;
import org.eclipse.kura.KuraException;
import org.eclipse.kura.core.testutil.requesthandler.AbstractRequestHandlerTest;
import org.eclipse.kura.core.testutil.requesthandler.MqttTransport;
Expand Down Expand Up @@ -83,7 +85,7 @@ public class IdentityEndpointsTest extends AbstractRequestHandlerTest {

private static final String EXPECTED_NON_EXISTING_USER_RESPONSE = new Scanner(
IdentityEndpointsTest.class.getResourceAsStream("/getNonExistingUserResponse.json"), "UTF-8")
.useDelimiter("\\A").next().replace(" ", "");
.useDelimiter("\\A").next();

private static Set<UserDTO> userConfigs;

Expand Down Expand Up @@ -187,7 +189,7 @@ public void shouldReturnNonExistingUserDeleteResponse() throws KuraException {
givenIdentityService();

whenRequestIsPerformed(new MethodSpec(METHOD_SPEC_DELETE, MQTT_METHOD_SPEC_DEL), "/identities",
"{\"userName\":\"nonExistingUser\"}");
gson.toJson(new UserDTO("nonExistingUser", null, false, false)));

thenResponseCodeIs(404);
thenResponseBodyEqualsJson(EXPECTED_NON_EXISTING_USER_RESPONSE);
Expand All @@ -198,7 +200,7 @@ public void shouldReturnNonExistingUserPostResponse() throws KuraException {
givenIdentityService();

whenRequestIsPerformed(new MethodSpec(METHOD_SPEC_POST), "/identities/byName",
"{\"userName\":\"nonExistingUser\"}");
gson.toJson(new UserDTO("nonExistingUser", null, false, false)));

thenResponseCodeIs(404);
thenResponseBodyEqualsJson(EXPECTED_NON_EXISTING_USER_RESPONSE);
Expand Down Expand Up @@ -226,8 +228,15 @@ private static void givenIdentityService() throws KuraException {

when(identityServiceMock.getUser("testuser"))
.thenReturn(new UserDTO("testuser", Collections.emptySet(), true, false));

}

when(identityServiceMock.getUser("nonExistingUser"))
.thenThrow(new KuraException(KuraErrorCode.NOT_FOUND, "Identity does not exist"));

doThrow(new KuraException(KuraErrorCode.NOT_FOUND, "Identity does not exist")).when(identityServiceMock)
.deleteUser("nonExistingUser");

when(identityServiceMock.getValidatorOptions()).thenReturn(new ValidatorOptions(8, false, false, false));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{
"message": "Identity does not exist"
}
{"message" : "Identity does not exist"}

0 comments on commit bf89c81

Please sign in to comment.