Commit de22d29d authored by 0Tyler's avatar 0Tyler

getPrivacyPolicyReportResponse

parent 1a3f8353
This diff is collapsed.
...@@ -56,9 +56,9 @@ public class DeviceController { ...@@ -56,9 +56,9 @@ public class DeviceController {
} }
//透過UDN讀取PrivacyPolicyReport //透過UDN讀取PrivacyPolicyReport
@GetMapping("/privacy/{UDN}") @GetMapping("/privacy/{udn}")
public ResponseEntity<PrivacyPolicyReport> readPrivacyPolicyReportByDevice(@PathVariable(value = "UDN") String UDN) { public ResponseEntity<PrivacyPolicyReport> readPrivacyPolicyReportByDevice(@PathVariable(value = "udn") String udn) {
return privacyPolicyReportService.readByDevice(UDN) return privacyPolicyReportService.readByDevice(udn)
.map(ResponseEntity::ok) .map(ResponseEntity::ok)
.orElseGet(()->ResponseEntity.noContent().build()); .orElseGet(()->ResponseEntity.noContent().build());
} }
......
package edu.prlab.tyler.iotgateway.cloud.controllers; package edu.prlab.tyler.iotgateway.cloud.controllers;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyContent;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicy;
import edu.prlab.tyler.iotgateway.cloud.services.PrivacyChoiceService; import edu.prlab.tyler.iotgateway.cloud.services.PrivacyChoiceService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
......
...@@ -20,7 +20,6 @@ public class PrivacyContent { ...@@ -20,7 +20,6 @@ public class PrivacyContent {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonIgnore
private long id; private long id;
@OneToOne(cascade = CascadeType.ALL) @OneToOne(cascade = CascadeType.ALL)
......
package edu.prlab.tyler.iotgateway.cloud.repositories; package edu.prlab.tyler.iotgateway.cloud.repositories;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyContent;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository @Repository
public interface PrivacyChoiceRepository extends CrudRepository<PrivacyChoice, Long> { public interface PrivacyChoiceRepository extends CrudRepository<PrivacyChoice, Long> {
Optional<Iterable<PrivacyChoice>> findPrivacyChoicesByPrivacyContent(PrivacyContent privacyContent);
} }
package edu.prlab.tyler.iotgateway.cloud.services; package edu.prlab.tyler.iotgateway.cloud.services;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicy;
import edu.prlab.tyler.iotgateway.cloud.repositories.PrivacyChoiceRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -9,16 +11,19 @@ import java.util.Optional; ...@@ -9,16 +11,19 @@ import java.util.Optional;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
@Service @Service
public class PrivacyChoiceService extends CrudService<PrivacyChoice, Long>{ public class PrivacyChoiceService extends CrudService<PrivacyChoice, Long> {
private PrivacyChoiceRepository privacyChoiceRepository;
@Autowired @Autowired
public PrivacyChoiceService(CrudRepository<PrivacyChoice, Long> repository) { public PrivacyChoiceService(CrudRepository<PrivacyChoice, Long> repository,
PrivacyChoiceRepository privacyChoiceRepository) {
super(repository); super(repository);
this.privacyChoiceRepository = privacyChoiceRepository;
} }
public Iterable<PrivacyChoice> readPrivacyChoiceByDevice(String udn) { public Iterable<PrivacyChoice> readPrivacyChoiceByDevice(String udn) {
return ()-> StreamSupport.stream(readll().spliterator(),false) return () -> StreamSupport.stream(readll().spliterator(), false)
.filter(choice->choice.getPrivacyContent().getDevice().getUdn().equals(udn)) .filter(choice -> choice.getPrivacyContent().getDevice().getUdn().equals(udn))
.iterator(); .iterator();
} }
} }
...@@ -220,5 +220,6 @@ public class CloudHttpApiTest { ...@@ -220,5 +220,6 @@ public class CloudHttpApiTest {
new TypeReference<Iterable<PrivacyChoice>>(){}); new TypeReference<Iterable<PrivacyChoice>>(){});
Assert.assertNotNull(privacyChoices); Assert.assertNotNull(privacyChoices);
} }
} }
...@@ -71,27 +71,6 @@ public class ContractTester { ...@@ -71,27 +71,6 @@ public class ContractTester {
String privacyPolicy = deviceContract.privacypolicy().send(); String privacyPolicy = deviceContract.privacypolicy().send();
Assert.assertNotNull(privacyPolicy); Assert.assertNotNull(privacyPolicy);
System.out.println(privacyPolicy); System.out.println(privacyPolicy);
//TODO CANNOT BIND
//Gateway
// GatewayContract gatewayContract = GatewayContract.deploy(quorum, manager, DEFAULT_GAS_PROVIDER).send();
// Assert.assertNotNull(gatewayContract);
// gateWayContractAddress = gatewayContract.getContractAddress();
// System.out.println("gatewayContract Address:" + gateWayContractAddress);
//
// receipt = deviceContract.setBuyer(gatewayContract.getContractAddress()).send();
// Assert.assertNotNull(receipt);
//
// Quorum quorum1 = Quorum.build(new HttpService(rpcUrl));
// String userAddress1 = quorum1.ethAccounts().send().getAccounts().get(quorum1.ethAccounts().send().getAccounts().size() - 1);
// ClientTransactionManager manager1 = new ClientTransactionManager(quorum1, userAddress1);
//
// System.out.println("deviceContractAddress" + deviceContractAddress);
// DeviceContract deviceContract1 = DeviceContract.load(deviceContractAddress, quorum1, manager1, DEFAULT_GAS_PROVIDER);
// System.out.println("deviceContractAddress" + gateWayContractAddress);
// receipt = deviceContract1.bindReq(gateWayContractAddress).send();
// Assert.assertNotNull(receipt);
// //
// String bindedString = deviceContract1.getBondDevice().send(); // String bindedString = deviceContract1.getBondDevice().send();
// Assert.assertNotNull(bindedString); // Assert.assertNotNull(bindedString);
...@@ -120,9 +99,20 @@ public class ContractTester { ...@@ -120,9 +99,20 @@ public class ContractTester {
Assert.assertNotNull(receipt); Assert.assertNotNull(receipt);
System.out.println(receipt); System.out.println(receipt);
//綁定裝置
System.out.println("綁定裝置");
receipt = gatewayContract.bindRequest(deviceContractAddress).send(); receipt = gatewayContract.bindRequest(deviceContractAddress).send();
Assert.assertNotNull(receipt); Assert.assertNotNull(receipt);
System.out.println(receipt); System.out.println(receipt);
//取得綁定裝置個數
BigInteger deviceNum = gatewayContract.numDevices().send();
Assert.assertNotNull(deviceNum);
System.out.println(deviceNum);
//取得第i個裝置的Address
String deviceAddress = gatewayContract.getDeviceAddress(BigInteger.ONE).send();
Assert.assertNotNull(deviceAddress);
System.out.println(deviceAddress);
} }
} }
...@@ -2,6 +2,7 @@ buildscript { ...@@ -2,6 +2,7 @@ buildscript {
ext { ext {
springBootVersion = '2.1.4.RELEASE' springBootVersion = '2.1.4.RELEASE'
mapstructVersion = '1.3.0.Final' mapstructVersion = '1.3.0.Final'
guavaVersion = '27.1-jre'
} }
repositories { repositories {
mavenCentral() mavenCentral()
...@@ -34,6 +35,7 @@ dependencies { ...@@ -34,6 +35,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation "org.mapstruct:mapstruct:${mapstructVersion}" implementation "org.mapstruct:mapstruct:${mapstructVersion}"
implementation "com.google.guava:guava:${guavaVersion}"
implementation project(":cloud") implementation project(":cloud")
compileOnly 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok'
......
...@@ -4,12 +4,15 @@ import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device; ...@@ -4,12 +4,15 @@ import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport;
import edu.prlab.tyler.iotgateway.gateway.model.PrivacyChoiceResponse; import edu.prlab.tyler.iotgateway.gateway.model.PrivacyChoiceResponse;
import edu.prlab.tyler.iotgateway.gateway.model.PrivacyPolicyReportResponse;
import edu.prlab.tyler.iotgateway.gateway.services.DeviceService; import edu.prlab.tyler.iotgateway.gateway.services.DeviceService;
import edu.prlab.tyler.iotgateway.gateway.services.PrivacyService; import edu.prlab.tyler.iotgateway.gateway.services.PrivacyService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Optional;
@RestController @RestController
public class GatewayController { public class GatewayController {
...@@ -44,10 +47,11 @@ public class GatewayController { ...@@ -44,10 +47,11 @@ public class GatewayController {
.orElseGet(() -> ResponseEntity.noContent().build()); .orElseGet(() -> ResponseEntity.noContent().build());
} }
//透過裝置UDN取得裝置資訊與隱私政策 //透過裝置UDN取得裝置資訊與隱私政策
@GetMapping("/privacy/{udn}") @GetMapping("/privacy/{udn}/{account}")
public ResponseEntity<PrivacyPolicyReport> readPrivacyPolicyReportByDevice(@PathVariable(value = "udn") String udn) { public ResponseEntity<PrivacyPolicyReportResponse> readPrivacyPolicyReportByDevice(@PathVariable String udn, @PathVariable String account) {
return privacyService.getRelatedPrivacyPolicies(udn) return privacyService.getRelatedPrivacyPolicyByUdn(udn, account)
.map(ResponseEntity::ok) .map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.noContent().build()); .orElseGet(() -> ResponseEntity.noContent().build());
} }
...@@ -64,8 +68,9 @@ public class GatewayController { ...@@ -64,8 +68,9 @@ public class GatewayController {
//根據使用者取得在此gateway上該使用者的隱私選擇列表 //根據使用者取得在此gateway上該使用者的隱私選擇列表
@GetMapping("/choice/{account}") @GetMapping("/choice/{account}")
public ResponseEntity<Iterable<PrivacyChoiceResponse>> readPrivacyChoiceRecordsByUser(@PathVariable String account) { public ResponseEntity<Iterable<PrivacyChoiceResponse>> readPrivacyChoiceRecordsByUser(@PathVariable String account) {
return privacyService.getPrivacyPolicyChoicesByAccount(account) return Optional.of(privacyService.getPrivacyPolicyChoicesByAccount(account))
.map(ResponseEntity::ok) .map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.noContent().build()); .orElseGet(() -> ResponseEntity.noContent().build());
} }
} }
package edu.prlab.tyler.iotgateway.gateway.model;
import edu.prlab.tyler.iotgateway.cloud.pojo.Document;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicy;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.util.HashMap;
import java.util.List;
@Getter
@Setter
@EqualsAndHashCode
@NoArgsConstructor
public class PrivacyPolicyReportResponse extends PrivacyPolicyReport {
private HashMap<Integer, Boolean> choices ;
@Builder(builderMethodName = "responseBuilder")
public PrivacyPolicyReportResponse(String id, String version, String description, Device device, List<PrivacyPolicy> policies, Document document, HashMap<Integer, Boolean> choices) {
super(id, version, description, device, policies, document);
this.choices = choices;
}
}
package edu.prlab.tyler.iotgateway.gateway.services; package edu.prlab.tyler.iotgateway.gateway.services;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Streams;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicy;
import edu.prlab.tyler.iotgateway.gateway.model.PrivacyChoiceResponse; import edu.prlab.tyler.iotgateway.gateway.model.PrivacyChoiceResponse;
import edu.prlab.tyler.iotgateway.gateway.model.PrivacyPolicyReportResponse;
import edu.prlab.tyler.iotgateway.gateway.pojo.PrivacyChoiceIndex; import edu.prlab.tyler.iotgateway.gateway.pojo.PrivacyChoiceIndex;
import edu.prlab.tyler.iotgateway.gateway.repositories.PrivacyChoiceIndexRepository; import edu.prlab.tyler.iotgateway.gateway.repositories.PrivacyChoiceIndexRepository;
import edu.prlab.tyler.iotgateway.gateway.repositories.UserRepository; import edu.prlab.tyler.iotgateway.gateway.repositories.UserRepository;
...@@ -10,8 +15,12 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -10,8 +15,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
@Service @Service
...@@ -28,34 +37,68 @@ public class PrivacyService { ...@@ -28,34 +37,68 @@ public class PrivacyService {
this.remoteService = remoteService; this.remoteService = remoteService;
} }
public Optional<PrivacyPolicyReport> getRelatedPrivacyPolicies(String udn) { // TODO 如果此User有表達過則回傳表達隱私政策與其表達,
return remoteService.readRelatedPrivacyPolicies(udn); public Optional<PrivacyPolicyReportResponse> getRelatedPrivacyPolicyByUdn(String udn, String account) {
return remoteService.readRelatedPrivacyPolicyReport(udn)
.flatMap(report -> Optional.ofNullable(this.findChoicesByPolicies(report.getPolicies(), udn, account))
.map(this::choicesToMap)
.map(choices -> PrivacyPolicyReportResponse.responseBuilder()
.id(report.getId())
.version(report.getVersion())
.description(report.getDescription())
.device(report.getDevice())
.policies(report.getPolicies())
.choices(choices)
.build()));
}
private List<Boolean> findChoicesByPolicies(List<PrivacyPolicy> privacyPolicies, String udn, String account) {
return privacyPolicies.stream()
.map(policy -> this.findPrivacyChoiceByPrivacyPolicy(policy, udn, account))
.map(choices -> (Iterables.isEmpty(choices)) ? Boolean.valueOf(false) : Iterables.getLast(choices).isAccepted())
.collect(Collectors.toList());
}
private HashMap<Integer, Boolean> choicesToMap(List<Boolean> choices) {
return Streams.mapWithIndex(choices.stream(),
(choice, index) -> Maps.newHashMap(ImmutableMap.of(Long.valueOf(index).intValue(), choice)))
.collect(HashMap::new, HashMap::putAll, HashMap::putAll);
}
private Iterable<PrivacyChoice> findPrivacyChoiceByPrivacyPolicy(PrivacyPolicy privacyPolicy, String udn, String account) {
return () -> StreamSupport.stream(remoteService.readPrivacyChoices().spliterator(), false)
.filter(choice -> choice.getPrivacyContent().getPolicy().getId().equals(privacyPolicy.getId()) &
choice.getPrivacyContent().getUser().getAccount().equals(account) &
choice.getPrivacyContent().getDevice().getUdn().equals(udn))
.collect(Collectors.toList()).iterator();
} }
public Optional<PrivacyChoiceResponse> setPrivacyChoice(PrivacyChoice privacyChoice) { public Optional<PrivacyChoiceResponse> setPrivacyChoice(PrivacyChoice privacyChoice) {
System.out.println("setPrivacyPolicyChoice : " + privacyChoice.toString());
return Optional.of(privacyChoice) return Optional.of(privacyChoice)
.flatMap(choice -> remoteService.setPrivacyChoice(choice)) .flatMap(choice -> remoteService.setPrivacyChoice(choice))
.flatMap(choice -> Optional.of(privacyChoiceIndexRepository.save(PrivacyChoiceIndex.builder() .flatMap(choice -> this.addPrivacyChoiceIndex(PrivacyChoiceIndex.builder()
.id(choice.getId()) .id(choice.getId())
.localDateTime(LocalDateTime.now()) .localDateTime(LocalDateTime.now())
.build())) .build())
.map(choiceIndex -> PrivacyChoiceResponse.builder() .map(choiceIndex -> PrivacyChoiceResponse.builder()
.id(choice.getId()) .id(choice.getId())
.localDateTime(LocalDateTime.now()) .localDateTime(choiceIndex.getLocalDateTime())
.privacyChoice(choice) .privacyChoice(choice)
.build())); .build()));
} }
private Optional<PrivacyChoiceIndex> addPrivacyChoiceIndex(PrivacyChoiceIndex choiceIndex) {
return Optional.ofNullable(privacyChoiceIndexRepository.save(choiceIndex));
}
// public Optional<Iterable<PrivacyChoice>> getPrivacyPolicyChoices() { // public Optional<Iterable<PrivacyChoice>> getPrivacyPolicyChoices() {
// return Optional.ofNullable(template.exchange(cloudAddress + "/choice", HttpMethod.GET, null, // return Optional.ofNullable(template.exchange(cloudAddress + "/choice", HttpMethod.GET, null,
// new ParameterizedTypeReference<Iterable<PrivacyChoice>>() { }).getBody()); // new ParameterizedTypeReference<Iterable<PrivacyChoice>>() { }).getBody());
// } // }
public Optional<Iterable<PrivacyChoiceResponse>> getPrivacyPolicyChoicesByAccount(String account) { public Iterable<PrivacyChoiceResponse> getPrivacyPolicyChoicesByAccount(String account) {
return remoteService.readPrivacyChoices() return () -> StreamSupport.stream(remoteService.readPrivacyChoices().spliterator(), false)
.map(choices -> StreamSupport.stream(choices.spliterator(), false) .filter(choice -> choice.getPrivacyContent().getUser().getAccount().equals(account))
.filter(privacyChoice -> privacyChoice.getPrivacyContent().getUser().getAccount().equals(account))
.map(choice -> privacyChoiceIndexRepository.findById(choice.getId()) .map(choice -> privacyChoiceIndexRepository.findById(choice.getId())
.map(choiceIndex -> PrivacyChoiceResponse.builder() .map(choiceIndex -> PrivacyChoiceResponse.builder()
.id(choiceIndex.getId()) .id(choiceIndex.getId())
...@@ -63,6 +106,7 @@ public class PrivacyService { ...@@ -63,6 +106,7 @@ public class PrivacyService {
.privacyChoice(choice) .privacyChoice(choice)
.build()) .build())
.orElseGet(() -> new PrivacyChoiceResponse())) .orElseGet(() -> new PrivacyChoiceResponse()))
.collect(Collectors.toList())); .collect(Collectors.toList())
.iterator();
} }
} }
...@@ -40,7 +40,7 @@ public class RemoteService { ...@@ -40,7 +40,7 @@ public class RemoteService {
}).getBody(), "Read devices error"); }).getBody(), "Read devices error");
} }
public Optional<PrivacyPolicyReport> readRelatedPrivacyPolicies(String udn) { public Optional<PrivacyPolicyReport> readRelatedPrivacyPolicyReport(String udn) {
return tryCatch(() -> template.exchange(cloudAddress + "/privacy/" + udn, HttpMethod.GET, null, return tryCatch(() -> template.exchange(cloudAddress + "/privacy/" + udn, HttpMethod.GET, null,
PrivacyPolicyReport.class).getBody(), "Read privacyPolicyReport error"); PrivacyPolicyReport.class).getBody(), "Read privacyPolicyReport error");
} }
...@@ -50,10 +50,11 @@ public class RemoteService { ...@@ -50,10 +50,11 @@ public class RemoteService {
new HttpEntity(choice), PrivacyChoice.class).getBody(), "Set privacyChoice error"); new HttpEntity(choice), PrivacyChoice.class).getBody(), "Set privacyChoice error");
} }
public Optional<Iterable<PrivacyChoice>> readPrivacyChoices() { public Iterable<PrivacyChoice> readPrivacyChoices() {
return tryCatch(() -> template.exchange(cloudAddress + "/choice", HttpMethod.GET, null, return tryCatch(() -> template.exchange(cloudAddress + "/choice", HttpMethod.GET, null,
new ParameterizedTypeReference<Iterable<PrivacyChoice>>() { new ParameterizedTypeReference<Iterable<PrivacyChoice>>() {
}).getBody(), "Read privacyChoice error"); }).getBody(), "Read privacyChoice error")
.orElse(null);
} }
public <T> Optional<T> tryCatch(Supplier<T> supplier, String errorMessage) { public <T> Optional<T> tryCatch(Supplier<T> supplier, String errorMessage) {
......
...@@ -7,6 +7,7 @@ import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device; ...@@ -7,6 +7,7 @@ import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyContent; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyContent;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport;
import edu.prlab.tyler.iotgateway.gateway.model.PrivacyPolicyReportResponse;
import edu.prlab.tyler.iotgateway.gateway.pojo.auth.SensitiveUser; import edu.prlab.tyler.iotgateway.gateway.pojo.auth.SensitiveUser;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -66,7 +67,7 @@ public class GatewayHttpApiTest { ...@@ -66,7 +67,7 @@ public class GatewayHttpApiTest {
.andDo(print()) .andDo(print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andReturn(); .andReturn();
Device device= mapper.readValue(result.getResponse().getContentAsString(), Device.class); Device device = mapper.readValue(result.getResponse().getContentAsString(), Device.class);
Assert.assertNotNull(device); Assert.assertNotNull(device);
//取得裝置清單 //取得裝置清單
...@@ -83,12 +84,12 @@ public class GatewayHttpApiTest { ...@@ -83,12 +84,12 @@ public class GatewayHttpApiTest {
//拿取隱私政策 //拿取隱私政策
result = mvc.perform(MockMvcRequestBuilders result = mvc.perform(MockMvcRequestBuilders
.get("/privacy/" + "a1252c49-4188-4e6d-a32e-66604c664fb8") .get("/privacy/" + "a1252c49-4188-4e6d-a32e-66604c664fb8/" + "test")
.accept(MediaType.APPLICATION_JSON_UTF8)) .accept(MediaType.APPLICATION_JSON_UTF8))
.andDo(print()) .andDo(print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andReturn(); .andReturn();
PrivacyPolicyReport report = mapper.readValue(result.getResponse().getContentAsString(), PrivacyPolicyReport.class); PrivacyPolicyReport report = mapper.readValue(result.getResponse().getContentAsString(), PrivacyPolicyReportResponse.class);
Assert.assertNotNull(report); Assert.assertNotNull(report);
//表達隱私偏好 //表達隱私偏好
...@@ -115,9 +116,18 @@ public class GatewayHttpApiTest { ...@@ -115,9 +116,18 @@ public class GatewayHttpApiTest {
Assert.assertNotNull(result); Assert.assertNotNull(result);
result = mvc.perform(MockMvcRequestBuilders
.get("/privacy/" + "a1252c49-4188-4e6d-a32e-66604c664fb8/" + "test")
.accept(MediaType.APPLICATION_JSON_UTF8))
.andDo(print())
.andExpect(status().isOk())
.andReturn();
report = mapper.readValue(result.getResponse().getContentAsString(), PrivacyPolicyReportResponse.class);
Assert.assertNotNull(report);
//取得所有隱私偏好 //取得所有隱私偏好
result = mvc.perform(MockMvcRequestBuilders result = mvc.perform(MockMvcRequestBuilders
.get("/choice"+"/test1") .get("/choice/" + privacyChoice.getPrivacyContent().getUser().getAccount())
.accept(MediaType.APPLICATION_JSON_UTF8)) .accept(MediaType.APPLICATION_JSON_UTF8))
.andDo(print()) .andDo(print())
.andExpect(status().isOk()) .andExpect(status().isOk())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment