-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
182 additions
and
30 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package oap.json; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAnyGetter; | ||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.ToString; | ||
import oap.json.properties.PropertiesDeserializer; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
@ToString | ||
@EqualsAndHashCode | ||
public abstract class AbstractProperties { | ||
@JsonIgnore | ||
private final LinkedHashMap<String, Object> properties = new LinkedHashMap<>(); | ||
|
||
@JsonAnySetter | ||
@JsonDeserialize( contentUsing = PropertiesDeserializer.class ) | ||
public void putProperty( String name, Object value ) { | ||
properties.put( name, value ); | ||
} | ||
|
||
@JsonAnyGetter | ||
public Map<String, Object> getProperties() { | ||
return properties; | ||
} | ||
|
||
@SuppressWarnings( "unchecked" ) | ||
@Nullable | ||
public <T> T getProperty( String property ) { | ||
return ( T ) properties.get( property ); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
oap-ws/oap-ws-admin-ws/src/main/java/oap/ws/admin/SchemaWS.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,23 @@ | ||
package oap.ws.admin; | ||
|
||
import oap.http.Http; | ||
import oap.json.Binder; | ||
import oap.json.schema.ResourceSchemaStorage; | ||
import oap.ws.Response; | ||
import oap.ws.WsMethod; | ||
import oap.ws.WsParam; | ||
|
||
import java.util.Map; | ||
|
||
import static oap.ws.WsParam.From.QUERY; | ||
|
||
public class SchemaWS { | ||
@WsMethod( path = "/" ) | ||
public Response getSchema( @WsParam( from = QUERY ) String path ) { | ||
String json = ResourceSchemaStorage.INSTANCE.get( path ); | ||
|
||
return new Response( Http.StatusCode.OK ) | ||
.withBody( Binder.json.marshalWithDefaultPrettyPrinter( Binder.json.unmarshal( Map.class, json ) ), true ) | ||
.withContentType( Http.ContentType.APPLICATION_JSON ); | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
oap-ws/oap-ws-admin-ws/src/test/java/oap/ws/admin/SchemaWSTest.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,62 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) Open Application Platform Authors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package oap.ws.admin; | ||
|
||
import oap.application.testng.KernelFixture; | ||
import oap.testng.Fixtures; | ||
import oap.testng.TestDirectoryFixture; | ||
import org.testng.annotations.Test; | ||
|
||
import static oap.http.test.HttpAsserts.assertGet; | ||
import static oap.io.Resources.urlOrThrow; | ||
|
||
public class SchemaWSTest extends Fixtures { | ||
private final KernelFixture kernel; | ||
|
||
public SchemaWSTest() { | ||
TestDirectoryFixture testDirectoryFixture = fixture( new TestDirectoryFixture() ); | ||
kernel = fixture( new KernelFixture( testDirectoryFixture, urlOrThrow( getClass(), "/application.test.conf" ) ) ); | ||
} | ||
|
||
@Test | ||
public void testSchema() { | ||
assertGet( kernel.httpUrl( "/system/admin/schema?path=/schema/test-schema.conf" ) ) | ||
.isOk() | ||
.respondedJson( """ | ||
{ | ||
"properties" : { | ||
"a" : { | ||
"type" : "string" | ||
}, | ||
"b" : { | ||
"type" : "string" | ||
} | ||
}, | ||
"type" : "object" | ||
} | ||
""" ); | ||
|
||
} | ||
} |
7 changes: 6 additions & 1 deletion
7
oap-ws/oap-ws-admin-ws/src/test/resources/application.test.conf
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
boot.main = oap-ws-admin-ws-test | ||
|
||
services { | ||
oap.oap-http-server.parameters.port = ${TEST_HTTP_PORT} | ||
oap-http { | ||
oap-http-server.parameters { | ||
defaultPort.httpPort = ${TEST_HTTP_PORT} | ||
additionalHttpPorts.httpprivate = ${TEST_HTTP_PORT} | ||
} | ||
} | ||
|
||
oap-ws.session-manager.parameters.cookieDomain: "" | ||
} |
6 changes: 6 additions & 0 deletions
6
oap-ws/oap-ws-admin-ws/src/test/resources/schema/test-schema.conf
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,6 @@ | ||
{ | ||
type = object | ||
properties { | ||
a.type = string | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
oap-ws/oap-ws-admin-ws/src/test/resources/schema/test-schema/test-schema.conf
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,5 @@ | ||
{ | ||
properties { | ||
b.type = string | ||
} | ||
} |
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