forked from OpenLiberty/open-liberty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request OpenLiberty#11 from a-saf/encodingAndHeader
For issue OpenLiberty#1660: Encoding and header validators and unit tests
- Loading branch information
Showing
5 changed files
with
196 additions
and
49 deletions.
There are no files selected for viewing
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
39 changes: 0 additions & 39 deletions
39
...rofile.openapi/src/com/ibm/ws/microprofile/openapi/impl/validation/EncodingValidator.java
This file was deleted.
Oops, something went wrong.
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
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
159 changes: 159 additions & 0 deletions
159
...penapi_test/test/com/ibm/ws/microprofile/openapi/validation/test/HeaderValidatorTest.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,159 @@ | ||
/* | ||
* IBM Confidential | ||
* | ||
* OCO Source Materials | ||
* | ||
* WLP Copyright IBM Corp. 2018 | ||
* | ||
* The source code for this program is not published or otherwise divested | ||
* of its trade secrets, irrespective of what has been deposited with the | ||
* U.S. Copyright Office. | ||
*/ | ||
package com.ibm.ws.microprofile.openapi.validation.test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.microprofile.openapi.models.examples.Example; | ||
import org.eclipse.microprofile.openapi.models.headers.Header; | ||
import org.eclipse.microprofile.openapi.models.headers.Header.Style; | ||
import org.junit.Test; | ||
|
||
import com.ibm.ws.microprofile.openapi.impl.model.OpenAPIImpl; | ||
import com.ibm.ws.microprofile.openapi.impl.model.examples.ExampleImpl; | ||
import com.ibm.ws.microprofile.openapi.impl.model.headers.HeaderImpl; | ||
import com.ibm.ws.microprofile.openapi.impl.model.media.ContentImpl; | ||
import com.ibm.ws.microprofile.openapi.impl.model.media.MediaTypeImpl; | ||
import com.ibm.ws.microprofile.openapi.impl.model.media.SchemaImpl; | ||
import com.ibm.ws.microprofile.openapi.impl.validation.HeaderValidator; | ||
import com.ibm.ws.microprofile.openapi.test.utils.TestValidationContextHelper; | ||
import com.ibm.ws.microprofile.openapi.test.utils.TestValidationHelper; | ||
import com.ibm.ws.microprofile.openapi.utils.OpenAPIModelWalker.Context; | ||
|
||
import junit.framework.Assert; | ||
|
||
/** | ||
* | ||
*/ | ||
public class HeaderValidatorTest { | ||
|
||
String key = null; | ||
OpenAPIImpl model = new OpenAPIImpl(); | ||
Context context = new TestValidationContextHelper(model); | ||
|
||
@Test | ||
public void testHeaderIsNull() { | ||
|
||
HeaderImpl headerIsNull = null; | ||
|
||
TestValidationHelper vh = new TestValidationHelper(); | ||
HeaderValidator validator = HeaderValidator.getInstance(); | ||
validator.validate(vh, context, key, headerIsNull); | ||
|
||
//Check for number of events only to keep assert statement independent of error message | ||
Assert.assertFalse(vh.hasEvents()); | ||
} | ||
|
||
@Test | ||
public void testExampleAndExamplesNotNull() { | ||
|
||
HeaderImpl exampleAndExamplesNotNull = new HeaderImpl(); | ||
exampleAndExamplesNotNull.setExample("testExample"); | ||
Map<String, Example> examples = new HashMap<String, Example>(); | ||
ExampleImpl example = new ExampleImpl(); | ||
example.setDescription("testExample"); | ||
examples.put(key, example); | ||
exampleAndExamplesNotNull.setExamples(examples); | ||
SchemaImpl schema = new SchemaImpl(); | ||
schema.setName("testSchema"); | ||
exampleAndExamplesNotNull.setSchema(schema); | ||
|
||
TestValidationHelper vh = new TestValidationHelper(); | ||
HeaderValidator validator = HeaderValidator.getInstance(); | ||
validator.validate(vh, context, key, exampleAndExamplesNotNull); | ||
|
||
//Check for number of events only to keep assert statement independent of error message | ||
Assert.assertEquals(1, vh.getEventsSize()); | ||
|
||
} | ||
|
||
@Test | ||
public void testSchemaAndContentNull() { | ||
|
||
HeaderImpl schemaAndContentNull = new HeaderImpl(); | ||
|
||
TestValidationHelper vh = new TestValidationHelper(); | ||
HeaderValidator validator = HeaderValidator.getInstance(); | ||
validator.validate(vh, context, key, schemaAndContentNull); | ||
|
||
//Check for number of events only to keep assert statement independent of error message | ||
Assert.assertEquals(1, vh.getEventsSize()); | ||
|
||
} | ||
|
||
@Test | ||
public void testSchemaAndContentNotNull() { | ||
|
||
HeaderImpl schemaAndContentNotNull = new HeaderImpl(); | ||
|
||
SchemaImpl schema = new SchemaImpl(); | ||
schema.setName("testSchema"); | ||
schemaAndContentNotNull.setSchema(schema); | ||
|
||
ContentImpl content = new ContentImpl(); | ||
MediaTypeImpl firstType = new MediaTypeImpl(); | ||
content.put("first", firstType); | ||
schemaAndContentNotNull.setContent(content); | ||
|
||
TestValidationHelper vh = new TestValidationHelper(); | ||
HeaderValidator validator = HeaderValidator.getInstance(); | ||
validator.validate(vh, context, key, schemaAndContentNotNull); | ||
|
||
//Check for number of events only to keep assert statement independent of error message | ||
Assert.assertEquals(1, vh.getEventsSize()); | ||
} | ||
|
||
@Test | ||
public void testContentMapWithTwoEntries() { | ||
|
||
HeaderImpl contentMapWithTwoEntries = new HeaderImpl(); | ||
|
||
ContentImpl content = new ContentImpl(); | ||
MediaTypeImpl firstType = new MediaTypeImpl(); | ||
MediaTypeImpl secondType = new MediaTypeImpl(); | ||
content.put("first", firstType); | ||
content.put("second", secondType); | ||
contentMapWithTwoEntries.setContent(content); | ||
|
||
TestValidationHelper vh = new TestValidationHelper(); | ||
HeaderValidator validator = HeaderValidator.getInstance(); | ||
validator.validate(vh, context, key, contentMapWithTwoEntries); | ||
|
||
//Check for number of events only to keep assert statement independent of error message | ||
Assert.assertEquals(1, vh.getEventsSize()); | ||
|
||
} | ||
|
||
@Test | ||
public void testCorrectHeader() { | ||
|
||
HeaderImpl correctHeader = new HeaderImpl(); | ||
|
||
Style style = Header.Style.SIMPLE; | ||
|
||
SchemaImpl schema = new SchemaImpl(); | ||
schema.setName("testSchema"); | ||
correctHeader.setSchema(schema); | ||
|
||
correctHeader.setStyle(style); | ||
|
||
TestValidationHelper vh = new TestValidationHelper(); | ||
HeaderValidator validator = HeaderValidator.getInstance(); | ||
validator.validate(vh, context, key, correctHeader); | ||
|
||
//Check for number of events only to keep assert statement independent of error message | ||
Assert.assertEquals(0, vh.getEventsSize()); | ||
|
||
} | ||
|
||
} |