-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[issue-325] - Add TCK tests to verify that DeploymentException is thr…
…own when HealthCheckResponse name is null or empty string
- Loading branch information
Showing
4 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
tck/src/main/java/org/eclipse/microprofile/health/tck/EmptyNameHealthCheckResponseTest.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,67 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICES file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.eclipse.microprofile.health.tck; | ||
|
||
import org.eclipse.microprofile.health.tck.deployment.EmptyNameCheck; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import jakarta.enterprise.inject.spi.DeploymentException; | ||
import jakarta.json.JsonArray; | ||
import jakarta.json.JsonObject; | ||
|
||
/** | ||
* @author Fabio Burzigotti | ||
*/ | ||
public class EmptyNameHealthCheckResponseTest extends TCKBase { | ||
|
||
@Deployment | ||
public static Archive getDeployment() { | ||
return DeploymentUtils.createWarFileWithClasses(EmptyNameHealthCheckResponseTest.class.getSimpleName(), | ||
EmptyNameCheck.class, TCKBase.class); | ||
} | ||
|
||
/** | ||
* Verifies that defining a HealthCheckResponse with an empty name will cause the runtime to throw a | ||
* {@link jakarta.enterprise.inject.spi.DeploymentException} | ||
*/ | ||
@Test | ||
@RunAsClient | ||
public void testStartupFailsWithException() { | ||
Response response = getUrlStartedContents(); | ||
|
||
// status code | ||
Assert.assertEquals(response.getStatus(), 503); | ||
|
||
JsonObject json = readJson(response); | ||
|
||
// response size | ||
JsonArray checks = json.getJsonArray("checks"); | ||
Assert.assertEquals(checks.size(), 1, "Expected a single check response"); | ||
|
||
assertOverallFailure(json); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
tck/src/main/java/org/eclipse/microprofile/health/tck/NullNameHealthCheckResponseTest.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,67 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICES file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.eclipse.microprofile.health.tck; | ||
|
||
import org.eclipse.microprofile.health.tck.deployment.NullNameCheck; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import jakarta.enterprise.inject.spi.DeploymentException; | ||
import jakarta.json.JsonArray; | ||
import jakarta.json.JsonObject; | ||
|
||
/** | ||
* @author Fabio Burzigotti | ||
*/ | ||
public class NullNameHealthCheckResponseTest extends TCKBase { | ||
|
||
@Deployment | ||
public static Archive getDeployment() { | ||
return DeploymentUtils.createWarFileWithClasses(NullNameHealthCheckResponseTest.class.getSimpleName(), | ||
NullNameCheck.class, TCKBase.class); | ||
} | ||
|
||
/** | ||
* Verifies that defining a HealthCheckResponse with a null name will cause the runtime to throw a | ||
* {@link DeploymentException} | ||
*/ | ||
@Test | ||
@RunAsClient | ||
public void testStartupFailsWithException() { | ||
Response response = getUrlStartedContents(); | ||
|
||
// status code | ||
Assert.assertEquals(response.getStatus(), 503); | ||
|
||
JsonObject json = readJson(response); | ||
|
||
// response size | ||
JsonArray checks = json.getJsonArray("checks"); | ||
Assert.assertEquals(checks.size(), 1, "Expected a single check response"); | ||
|
||
assertOverallFailure(json); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tck/src/main/java/org/eclipse/microprofile/health/tck/deployment/EmptyNameCheck.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,37 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICES file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package org.eclipse.microprofile.health.tck.deployment; | ||
|
||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
import org.eclipse.microprofile.health.Startup; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@Startup | ||
@ApplicationScoped | ||
public class EmptyNameCheck implements HealthCheck { | ||
@Override | ||
public HealthCheckResponse call() { | ||
return HealthCheckResponse.up(""); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tck/src/main/java/org/eclipse/microprofile/health/tck/deployment/NullNameCheck.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,37 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICES file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package org.eclipse.microprofile.health.tck.deployment; | ||
|
||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
import org.eclipse.microprofile.health.Startup; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@Startup | ||
@ApplicationScoped | ||
public class NullNameCheck implements HealthCheck { | ||
@Override | ||
public HealthCheckResponse call() { | ||
return HealthCheckResponse.up(null); | ||
} | ||
} |