forked from eclipse-ditto/ditto
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eclipse-ditto#964] add SubjectExpiryNotification and annotation-base…
…d serialization. Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
- Loading branch information
Showing
20 changed files
with
848 additions
and
4 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
49 changes: 49 additions & 0 deletions
49
model/base/src/main/java/org/eclipse/ditto/model/base/json/JsonParsableNotification.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,49 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.model.base.json; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.atteo.classindex.IndexAnnotated; | ||
|
||
/** | ||
* This annotated marks a notification as deserializable from Json when calling the specified | ||
* {@link org.eclipse.ditto.model.base.json.JsonParsableNotification#method()} with {@link org.eclipse.ditto.json.JsonObject} as first | ||
* and {@link org.eclipse.ditto.model.base.headers.DittoHeaders} as second argument. | ||
* The {@link org.eclipse.ditto.model.base.json.JsonParsableNotification#type()} is used as identifier of this notification. | ||
*/ | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@IndexAnnotated | ||
public @interface JsonParsableNotification { | ||
|
||
/** | ||
* Used as identifier of the exception. | ||
* | ||
* @return the error code. | ||
*/ | ||
String type(); | ||
|
||
/** | ||
* The name of the method accepting a {@link org.eclipse.ditto.json.JsonObject} as first argument and | ||
* {@link org.eclipse.ditto.model.base.headers.DittoHeaders} as seconds argument. | ||
* The Method must return an instance of the exception annotated with this annotation. | ||
* | ||
* @return the name of this method. | ||
*/ | ||
String method() default "fromJson"; | ||
|
||
} |
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
54 changes: 54 additions & 0 deletions
54
...ava/org/eclipse/ditto/services/models/connectivity/ConnectivityMappingStrategiesTest.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,54 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.services.models.connectivity; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.Instant; | ||
import java.util.Collections; | ||
|
||
import org.eclipse.ditto.json.JsonObject; | ||
import org.eclipse.ditto.model.base.auth.AuthorizationSubject; | ||
import org.eclipse.ditto.model.base.headers.DittoHeaders; | ||
import org.eclipse.ditto.model.base.json.Jsonifiable; | ||
import org.eclipse.ditto.model.policies.PolicyId; | ||
import org.eclipse.ditto.services.models.policies.PoliciesMappingStrategies; | ||
import org.eclipse.ditto.signals.notifications.policies.SubjectExpiryNotification; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests {@link ConnectivityMappingStrategies}. | ||
*/ | ||
public final class ConnectivityMappingStrategiesTest { | ||
|
||
@Test | ||
public void deserializeSubjectExpiryNotification() { | ||
final Instant expiry = Instant.now(); | ||
final DittoHeaders dittoHeaders = DittoHeaders.newBuilder().randomCorrelationId().build(); | ||
final SubjectExpiryNotification notification = SubjectExpiryNotification.of( | ||
PolicyId.of("policy:id"), | ||
expiry, | ||
Collections.singleton(AuthorizationSubject.newInstance("ditto:ditto")), | ||
dittoHeaders | ||
); | ||
|
||
final JsonObject json = notification.toJson(); | ||
final PoliciesMappingStrategies underTest = PoliciesMappingStrategies.getInstance(); | ||
final Jsonifiable<?> output = underTest.getMappingStrategy(notification.getManifest()) | ||
.orElseThrow() | ||
.parse(json, dittoHeaders); | ||
|
||
assertThat(output).isEqualTo(notification); | ||
} | ||
|
||
} |
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
52 changes: 52 additions & 0 deletions
52
...c/test/java/org/eclipse/ditto/services/models/policies/PoliciesMappingStrategiesTest.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,52 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.services.models.policies; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.Instant; | ||
import java.util.Collections; | ||
|
||
import org.eclipse.ditto.json.JsonObject; | ||
import org.eclipse.ditto.model.base.auth.AuthorizationSubject; | ||
import org.eclipse.ditto.model.base.headers.DittoHeaders; | ||
import org.eclipse.ditto.model.base.json.Jsonifiable; | ||
import org.eclipse.ditto.model.policies.PolicyId; | ||
import org.eclipse.ditto.signals.notifications.policies.SubjectExpiryNotification; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests {@link PoliciesMappingStrategies}. | ||
*/ | ||
public final class PoliciesMappingStrategiesTest { | ||
|
||
@Test | ||
public void deserializeSubjectExpiryNotification() { | ||
final Instant expiry = Instant.now(); | ||
final DittoHeaders dittoHeaders = DittoHeaders.newBuilder().randomCorrelationId().build(); | ||
final SubjectExpiryNotification notification = SubjectExpiryNotification.of( | ||
PolicyId.of("policy:id"), | ||
expiry, | ||
Collections.singleton(AuthorizationSubject.newInstance("ditto:ditto")), | ||
dittoHeaders | ||
); | ||
|
||
final JsonObject json = notification.toJson(); | ||
final PoliciesMappingStrategies underTest = PoliciesMappingStrategies.getInstance(); | ||
final Jsonifiable<?> output = underTest.getMappingStrategy(notification.getManifest()) | ||
.orElseThrow() | ||
.parse(json, dittoHeaders); | ||
|
||
assertThat(output).isEqualTo(notification); | ||
} | ||
} |
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
Oops, something went wrong.