-
Notifications
You must be signed in to change notification settings - Fork 215
/
PolicyPersistenceOperationsActorIT.java
135 lines (114 loc) · 5.1 KB
/
PolicyPersistenceOperationsActorIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* 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.policies.service.persistence.actors;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import org.eclipse.ditto.base.model.auth.AuthorizationContext;
import org.eclipse.ditto.base.model.auth.AuthorizationSubject;
import org.eclipse.ditto.base.model.auth.DittoAuthorizationContextType;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.internal.utils.persistence.mongo.ops.eventsource.MongoEventSourceITAssertions;
import org.eclipse.ditto.internal.utils.pubsub.DistributedPub;
import org.eclipse.ditto.policies.model.EffectedPermissions;
import org.eclipse.ditto.policies.model.Policy;
import org.eclipse.ditto.policies.model.PolicyId;
import org.eclipse.ditto.policies.model.Resource;
import org.eclipse.ditto.policies.model.SubjectType;
import org.eclipse.ditto.policies.model.signals.commands.PolicyCommand;
import org.eclipse.ditto.policies.model.signals.commands.exceptions.PolicyNotAccessibleException;
import org.eclipse.ditto.policies.model.signals.commands.modify.CreatePolicy;
import org.eclipse.ditto.policies.model.signals.commands.modify.CreatePolicyResponse;
import org.eclipse.ditto.policies.model.signals.commands.query.RetrievePolicy;
import org.eclipse.ditto.policies.model.signals.commands.query.RetrievePolicyResponse;
import org.eclipse.ditto.policies.service.persistence.serializer.PolicyMongoSnapshotAdapter;
import org.eclipse.ditto.utils.jsr305.annotations.AllValuesAreNonnullByDefault;
import org.junit.Test;
import org.mockito.Mockito;
import com.typesafe.config.Config;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
/**
* Tests {@link org.eclipse.ditto.policies.service.persistence.actors.PolicyPersistenceOperationsActor}.
*/
@AllValuesAreNonnullByDefault
public final class PolicyPersistenceOperationsActorIT extends MongoEventSourceITAssertions<PolicyId> {
private static final AuthorizationContext AUTHORIZATION_CONTEXT =
AuthorizationContext.newInstance(DittoAuthorizationContextType.UNSPECIFIED,
AuthorizationSubject.newInstance("ditto:random-subject"));
@Test
public void purgeNamespaceWithoutSuffix() {
assertPurgeNamespace();
}
@Test
public void purgeEntitiesWithNamespace() {
assertPurgeEntitiesWithNamespace();
}
@Override
protected String getServiceName() {
// this loads the policies.conf as ActorSystem conf
return "policies";
}
@Override
protected String getResourceType() {
return PolicyCommand.RESOURCE_TYPE;
}
@Override
protected PolicyId toEntityId(final CharSequence entityId) {
return PolicyId.of(entityId);
}
@Override
protected Object getCreateEntityCommand(final PolicyId id) {
final Policy policy = Policy.newBuilder(id)
.forLabel("DUMMY")
.setSubject("ditto:random-subject", SubjectType.GENERATED)
.setResource(Resource.newInstance(PolicyCommand.RESOURCE_TYPE, "/",
EffectedPermissions.newInstance(Arrays.asList("READ", "WRITE"), Collections.emptyList())))
.build();
return CreatePolicy.of(policy, DittoHeaders.newBuilder()
.authorizationContext(AUTHORIZATION_CONTEXT)
.build());
}
@Override
protected Class<?> getCreateEntityResponseClass() {
return CreatePolicyResponse.class;
}
@Override
protected Object getRetrieveEntityCommand(final PolicyId id) {
return RetrievePolicy.of(id, DittoHeaders.newBuilder()
.authorizationContext(AUTHORIZATION_CONTEXT)
.build());
}
@Override
protected Class<?> getRetrieveEntityResponseClass() {
return RetrievePolicyResponse.class;
}
@Override
protected Class<?> getEntityNotAccessibleClass() {
return PolicyNotAccessibleException.class;
}
@Override
protected ActorRef startActorUnderTest(final ActorSystem actorSystem, final ActorRef pubSubMediator,
final Config config) {
final Props opsActorProps = PolicyPersistenceOperationsActor.props(pubSubMediator, mongoDbConfig, config,
persistenceOperationsConfig);
return actorSystem.actorOf(opsActorProps, PolicyPersistenceOperationsActor.ACTOR_NAME);
}
@Override
protected ActorRef startEntityActor(final ActorSystem system, final ActorRef pubSubMediator, final PolicyId id) {
final Props props = PolicySupervisorActor.props(pubSubMediator, new PolicyMongoSnapshotAdapter(),
Mockito.mock(DistributedPub.class), null, CompletableFuture::completedStage);
return system.actorOf(props, id.toString());
}
}