Skip to content

Commit b6a3f88

Browse files
committed
Cleaned up test data model
1 parent 485287a commit b6a3f88

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/f01auth/FineGrainedAuthTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ private static String resourceUrl(String path, String name) {
132132
}
133133

134134
private static final SensorThingsSensingV11 mdlSensing = new SensorThingsSensingV11();
135-
private static final SensorThingsUserModel mdlUsers = new SensorThingsUserModel(mdlSensing);
135+
private static final SensorThingsUserModel mdlUsers = new SensorThingsUserModel();
136+
private static final SensorThingsService baseService = new SensorThingsService(mdlSensing, mdlUsers);
136137

137138
private static final List<Entity> THINGS = new ArrayList<>();
138139
private static final List<Entity> LOCATIONS = new ArrayList<>();
@@ -264,7 +265,7 @@ private String typeFromSelfLink(String selfLink) {
264265

265266
private SensorThingsService createService() {
266267
try {
267-
return new SensorThingsService(mdlUsers.getModelRegistry())
268+
return new SensorThingsService(baseService.getModelRegistry())
268269
.setEndpoint(new URL(serverSettings.getServiceUrl(version)));
269270
} catch (MalformedURLException ex) {
270271
throw new IllegalArgumentException("Serversettings contains malformed URL.", ex);

FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/f01auth/SensorThingsUserModel.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@
2828
import de.fraunhofer.iosb.ilt.frostclient.model.Entity;
2929
import de.fraunhofer.iosb.ilt.frostclient.model.EntityType;
3030
import de.fraunhofer.iosb.ilt.frostclient.model.ModelRegistry;
31+
import de.fraunhofer.iosb.ilt.frostclient.model.property.EntityProperty;
3132
import de.fraunhofer.iosb.ilt.frostclient.model.property.EntityPropertyMain;
3233
import de.fraunhofer.iosb.ilt.frostclient.model.property.NavigationPropertyEntity;
3334
import de.fraunhofer.iosb.ilt.frostclient.model.property.NavigationPropertyEntitySet;
34-
import de.fraunhofer.iosb.ilt.frostclient.models.SensorThingsSensingV11;
35+
import de.fraunhofer.iosb.ilt.frostclient.models.DataModel;
3536
import de.fraunhofer.iosb.ilt.frostclient.models.ext.MapValue;
3637
import java.util.Map;
3738

3839
/**
3940
*
4041
*/
41-
public class SensorThingsUserModel {
42+
public class SensorThingsUserModel implements DataModel {
4243

4344
private static final String NAME_USER = "User";
4445
private static final String NAME_USERS = "Users";
@@ -53,9 +54,9 @@ public class SensorThingsUserModel {
5354
private static final String NAME_EP_USERPASS = "userpass";
5455
private static final String NAME_EP_ROLENAME = "rolename";
5556

56-
public static final EntityPropertyMain<String> EP_USERNAME = new EntityPropertyMain<>(NAME_EP_USERNAME, EDM_STRING);
57-
public static final EntityPropertyMain<String> EP_USERPASS = new EntityPropertyMain<>(NAME_EP_USERPASS, EDM_STRING);
58-
public static final EntityPropertyMain<String> EP_ROLENAME = new EntityPropertyMain<>(NAME_EP_ROLENAME, EDM_STRING);
57+
public static final EntityProperty<String> EP_USERNAME = new EntityPropertyMain<>(NAME_EP_USERNAME, EDM_STRING);
58+
public static final EntityProperty<String> EP_USERPASS = new EntityPropertyMain<>(NAME_EP_USERPASS, EDM_STRING);
59+
public static final EntityProperty<String> EP_ROLENAME = new EntityPropertyMain<>(NAME_EP_ROLENAME, EDM_STRING);
5960

6061
public final NavigationPropertyEntitySet npUserRoles = new NavigationPropertyEntitySet(NAME_ROLES);
6162
public final NavigationPropertyEntitySet npUserUserprojectroles = new NavigationPropertyEntitySet(NAME_USERPROJECTROLES);
@@ -77,14 +78,19 @@ public class SensorThingsUserModel {
7778
public final EntityType etProject = new EntityType(NAME_PROJECT, NAME_PROJECTS);
7879
public final EntityType etUserProjectRole = new EntityType(NAME_USERPROJECTROLE, NAME_USERPROJECTROLES);
7980

80-
public final ModelRegistry mr;
81+
public ModelRegistry mr;
8182

82-
public SensorThingsUserModel(SensorThingsSensingV11 modelSensing) {
83-
this(modelSensing.getModelRegistry());
83+
public SensorThingsUserModel() {
8484
}
8585

86-
public SensorThingsUserModel(ModelRegistry mrSensing) {
87-
this.mr = mrSensing;
86+
@Override
87+
public final void init(ModelRegistry modelRegistry) {
88+
if (this.mr != null) {
89+
throw new IllegalArgumentException("Already initialised.");
90+
}
91+
this.mr = modelRegistry;
92+
mr.addDataModel(this);
93+
8894
mr.registerEntityType(etUser);
8995
mr.registerEntityType(etRole);
9096
mr.registerEntityType(etProject);
@@ -120,6 +126,11 @@ public SensorThingsUserModel(ModelRegistry mrSensing) {
120126
mr.getEntityTypeForName(NAME_THING).registerProperty(npThingProjects);
121127
}
122128

129+
@Override
130+
public boolean isInitialised() {
131+
return mr != null;
132+
}
133+
123134
public ModelRegistry getModelRegistry() {
124135
return mr;
125136
}

0 commit comments

Comments
 (0)