Skip to content
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

feat(iot-service): Add mapping for 409 status code to IotHubConflictException #548

Merged
merged 2 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/

package com.microsoft.azure.sdk.iot.service.exceptions;

/**
* 409 Conflict
* Likely caused by trying to create a resource that already exists
*/
public class IotHubConflictException extends IotHubException
{
public IotHubConflictException()
{
this(null);
}

public IotHubConflictException(String message)
{
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ else if (404 == responseStatus)
{
throw new IotHubNotFoundException(errorMessage);
}
// Codes_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_34_018: [The function shall throw IotHubConflictException if the Http response status equal 409]
else if (409 == responseStatus)
{
throw new IotHubConflictException(errorMessage);
}
// Codes_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_12_005: [The function shall throw IotHubPreconditionFailedException if the Http response status equal 412]
else if (412 == responseStatus)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ public void httpResponseVerification404() throws IotHubException
IotHubExceptionManager.httpResponseVerification(response);
}

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_34_018: [The function shall throw IotHubConflictException if the Http response status equal 409]
// Assert
@Test (expected = IotHubConflictException.class)
public void httpResponseVerification409() throws IotHubException
{
// Arrange
final int status = 409;
final byte[] body = { 1 };
final Map<String, List<String>> headerFields = new HashMap<>();
final byte[] errorReason = { 2, 3, 4, 5 };
HttpResponse response = new HttpResponse(status, body, headerFields, errorReason);
// Act
IotHubExceptionManager.httpResponseVerification(response);
}

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBEXCEPTIONMANAGER_12_005: [The function shall throw IotHubPreconditionFailedException if the Http response status equal 412]
// Assert
@Test (expected = IotHubPreconditionFailedException.class)
Expand Down