Commit 1e8237b6 authored by 0Tyler's avatar 0Tyler

deviceContractTest

parent 48377c5d
......@@ -16,6 +16,17 @@
<option name="useAutoImport" value="true" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$/contract" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$/contract" />
</set>
</option>
<option name="useAutoImport" value="true" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
buildscript {
ext{
ext {
springBootVersion = '2.1.4.RELEASE'
mapstructVersion = '1.3.0.Final'
jwtVersion = '3.5.0'
jjwtVersion = '0.9.1'
}
repositories {
mavenCentral()
......@@ -31,9 +35,12 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
implementation "org.mapstruct:mapstruct:${mapstructVersion}"
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
package edu.prlab.tyler.iotgateway.cloud.config;
import edu.prlab.tyler.iotgateway.cloud.pojo.auth.SensitiveUser;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Manufacturer;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Model;
......@@ -8,6 +9,7 @@ import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.p3p.*;
import edu.prlab.tyler.iotgateway.cloud.services.DeviceService;
import edu.prlab.tyler.iotgateway.cloud.services.PrivacyPolicyReportService;
import edu.prlab.tyler.iotgateway.cloud.services.SensitiveUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
......@@ -15,25 +17,31 @@ import org.springframework.stereotype.Component;
import java.util.Arrays;
import static java.util.Arrays.asList;
@Component
public class DefaultData implements ApplicationRunner {
private DeviceService deviceService;
private PrivacyPolicyReportService privacyPolicyReportService;
// private SensitiveUserService sensitiveUserService;
@Autowired
public DefaultData(DeviceService deviceService,
PrivacyPolicyReportService privacyPolicyReportService) {
PrivacyPolicyReportService privacyPolicyReportService,
SensitiveUserService sensitiveUserService) {
this.deviceService = deviceService;
this.privacyPolicyReportService = privacyPolicyReportService;
// this.sensitiveUserService = sensitiveUserService;
}
@Override
public void run(ApplicationArguments args) {
// SensitiveUser user = SensitiveUser.builder()
// .username("test")
// .password("test")
// .build();
// sensitiveUserService.add(user);
Device oxygenDevice = Device.builder()
.udn("a1252c49-4188-4e6d-a32e-66604c664fb8")
......@@ -112,4 +120,7 @@ public class DefaultData implements ApplicationRunner {
privacyPolicyReportService.add(oxygenPrivacyPolicyReport);
}
}
\ No newline at end of file
package edu.prlab.tyler.iotgateway.cloud.controllers;
import edu.prlab.tyler.iotgateway.cloud.pojo.auth.SensitiveUser;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyPolicyReport;
import edu.prlab.tyler.iotgateway.cloud.services.DeviceService;
import edu.prlab.tyler.iotgateway.cloud.services.PrivacyPolicyReportService;
import org.assertj.core.util.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@RestController
......@@ -37,9 +41,16 @@ public class DeviceController {
.orElseGet(()->ResponseEntity.noContent().build());
}
// @GetMapping
// public ResponseEntity<Iterable<Device>> readDevices() {
// return Optional.of(deviceService.readll())
// .map(ResponseEntity::ok)
// .orElseGet(()->ResponseEntity.noContent().build());
// }
@GetMapping
public ResponseEntity<Iterable<Device>> readDevices() {
return Optional.of(deviceService.readll())
public ResponseEntity<ArrayList<Device>> readDevices(SensitiveUser user) {
return Optional.of(Lists.newArrayList(deviceService.readll()))
.map(ResponseEntity::ok)
.orElseGet(()->ResponseEntity.noContent().build());
}
......
package edu.prlab.tyler.iotgateway.cloud.controllers;
import edu.prlab.tyler.iotgateway.cloud.pojo.auth.SensitiveUser;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.services.PrivacyChoiceService;
import edu.prlab.tyler.iotgateway.cloud.services.SensitiveUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -11,12 +13,17 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
public class GatewayController {
private PrivacyChoiceService privacyChoiceService;
private SensitiveUserService sensitiveUserService;
@Autowired
public GatewayController(PrivacyChoiceService privacyChoiceService) {
public GatewayController(PrivacyChoiceService privacyChoiceService,
SensitiveUserService sensitiveUserService) {
this.privacyChoiceService = privacyChoiceService;
this.sensitiveUserService = sensitiveUserService;
}
@PostMapping("/choice")
public ResponseEntity<PrivacyChoice> setPrivacyChoice(@RequestBody PrivacyChoice privacyChoice) {
return privacyChoiceService.add(privacyChoice)
......@@ -24,4 +31,11 @@ public class GatewayController {
.orElseGet(() -> ResponseEntity.noContent().build());
}
@PostMapping("user")
public ResponseEntity<SensitiveUser> setUser(@RequestBody SensitiveUser sensitiveUser) {
return sensitiveUserService.add(sensitiveUser)
.map(ResponseEntity::ok)
.orElseGet(()->ResponseEntity.noContent().build());
}
}
package edu.prlab.tyler.iotgateway.cloud.pojo.auth;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.*;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.math.BigInteger;
@Data
......@@ -19,14 +14,16 @@ import java.math.BigInteger;
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class User {
public class SensitiveUser {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonIgnore
private int id;
private String account;
private long id;
private String username;
private String password;
private BigInteger publicKey;
private BigInteger privateKey;
private String address;
// private BigInteger publicKey;
// private BigInteger privateKey;
// private String address;
}
package edu.prlab.tyler.iotgateway.cloud.pojo.privacy;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sun.xml.internal.ws.api.pipe.ContentType;
import edu.prlab.tyler.iotgateway.cloud.pojo.auth.User;
import edu.prlab.tyler.iotgateway.cloud.pojo.auth.SensitiveUser;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device;
import lombok.AllArgsConstructor;
import lombok.Builder;
......@@ -26,7 +25,7 @@ public class PrivacyContent {
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id")
private User user;
private SensitiveUser user;
@OneToOne
@JoinColumn(name = "device_id")
......
package edu.prlab.tyler.iotgateway.cloud.repositories;
import edu.prlab.tyler.iotgateway.cloud.pojo.auth.SensitiveUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface SensitiveUserRepository extends JpaRepository<SensitiveUser, Long> {
}
......@@ -2,6 +2,7 @@ package edu.prlab.tyler.iotgateway.cloud.services;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
import java.util.Optional;
public abstract class CrudService<T , ID> {
......@@ -12,6 +13,7 @@ public abstract class CrudService<T , ID> {
}
public Optional<T> add(T pojo) {
System.out.println(pojo.toString());
return Optional.of(repository.save(pojo));
}
......
package edu.prlab.tyler.iotgateway.cloud.services;
import edu.prlab.tyler.iotgateway.cloud.pojo.auth.SensitiveUser;
import edu.prlab.tyler.iotgateway.cloud.repositories.SensitiveUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
public class SensitiveUserService {
private SensitiveUserRepository repository;
@Autowired
public SensitiveUserService(SensitiveUserRepository repository) {
this.repository = repository;
}
public Optional<SensitiveUser> add(SensitiveUser pojo) {
System.out.println(pojo.toString());
return Optional.of(repository.saveAndFlush(pojo));
}
}
package edu.prlab.tyler.iotgateway.cloud;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.prlab.tyler.iotgateway.cloud.pojo.auth.User;
import edu.prlab.tyler.iotgateway.cloud.pojo.auth.SensitiveUser;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Icon;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Model;
......@@ -22,10 +24,9 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import static java.util.Arrays.asList;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
......@@ -44,6 +45,7 @@ public class CloudHttpApiTest {
.webAppContextSetup(context)
.build();
this.mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
}
@Test
......@@ -73,7 +75,6 @@ public class CloudHttpApiTest {
.andDo(print())
.andExpect(status().isOk())
.andReturn();
device = mapper.readValue(result.getResponse().getContentAsString(), Device.class);
Assert.assertNotNull(device);
......@@ -83,7 +84,6 @@ public class CloudHttpApiTest {
.andDo(print())
.andExpect(status().isOk())
.andReturn();
device = mapper.readValue(result.getResponse().getContentAsString(), Device.class);
Assert.assertNotNull(device);
......@@ -93,33 +93,31 @@ public class CloudHttpApiTest {
.andDo(print())
.andExpect(status().isOk())
.andReturn();
Assert.assertNotNull(result);
ArrayList<Device> devices = mapper.readValue(result.getResponse().getContentAsString(),
new TypeReference<ArrayList<Device>>() {});
Assert.assertNotNull(devices);
result = mvc.perform(MockMvcRequestBuilders
.get("/device/privacy/" + "a1252c49-4188-4e6d-a32e-66604c664fb8")
.get("/device/privacy/" + device.getUdn())
.accept(MediaType.APPLICATION_JSON_UTF8))
.andDo(print())
.andExpect(status().isOk())
.andReturn();
PrivacyPolicyReport report = mapper.readValue(result.getResponse().getContentAsString(), PrivacyPolicyReport.class);
Assert.assertNotNull(report);
PrivacyChoice privacyChoice = PrivacyChoice.builder()
.privacyContent(PrivacyContent.builder()
.user(User.builder()
.account("test")
.user(SensitiveUser.builder()
.username("test")
.password("test")
.publicKey(BigInteger.ONE)
.privateKey(BigInteger.ONE)
.address("test Address").build())
.build())
.device(device)
.policy(report.getPolicies().get(0))
.build())
.isAccepted(true)
.build();
mapper.writeValueAsString(privacyChoice);
result = mvc.perform(MockMvcRequestBuilders
.post("/choice")
.contentType(MediaType.APPLICATION_JSON_UTF8)
......
HELP.md
.gradle
/build/
!gradle/wrapper/gradle-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
/out/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
plugins {
id 'org.springframework.boot' version '2.1.4.RELEASE'
id 'java'
}
ext {
web3jQuorumVersion = '4.0.6'
}
apply plugin: 'io.spring.dependency-management'
group = 'edu.prlab.tyler.iotgateway'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation "org.web3j:quorum:${web3jQuorumVersion}"
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testCompile("org.junit.jupiter:junit-jupiter-api:5.4.2")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.2")
}
#Mon Apr 29 13:41:54 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
pluginManagement {
repositories {
gradlePluginPortal()
}
}
rootProject.name = 'contract'
package edu.prlab.tyler.iotgateway.contract;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ContractApplication {
public static void main(String[] args) {
SpringApplication.run(ContractApplication.class, args);
}
}
package edu.prlab.tyler.iotgateway.contract;
import io.reactivex.Flowable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.web3j.abi.EventEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Event;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.Utf8String;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.request.EthFilter;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;
import org.web3j.tx.gas.ContractGasProvider;
/**
* <p>Auto generated code.
* <p><strong>Do not modify!</strong>
* <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
* or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the
* <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
*
* <p>Generated with web3j version 4.2.0.
*/
public class DeviceContract extends Contract {
private static final String BINARY = "60008054600160a060020a0319163317905560c0604052601060808190527f64657669636520696e666f20746573740000000000000000000000000000000060a090815261005091600191906100ba565b506040805180820190915260128082527f7072697661637920706f6c696379202e2e2e00000000000000000000000000006020909201918252610095916002916100ba565b5060048054600160a060020a031916331790553480156100b457600080fd5b50610155565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100fb57805160ff1916838001178555610128565b82800160010185558215610128579182015b8281111561012857825182559160200191906001019061010d565b50610134929150610138565b5090565b61015291905b80821115610134576000815560010161013e565b90565b610692806101646000396000f3006080604052600436106100a35763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663320f201e81146100a857806341c0e1b51461010357806364beeaea146101185780637b6fe4ce146101495780638da5cb5b1461015e578063a3f09ad614610173578063a3f6774d14610194578063acc90f79146101b5578063dc0453041461020e578063eec56ecf14610298575b600080fd5b3480156100b457600080fd5b506040805160206004803580820135601f81018490048402850184019095528484526101019436949293602493928401919081908401838280828437509497506102ad9650505050505050565b005b34801561010f57600080fd5b50610101610304565b34801561012457600080fd5b5061012d610329565b60408051600160a060020a039092168252519081900360200190f35b34801561015557600080fd5b5061012d610339565b34801561016a57600080fd5b5061012d610348565b34801561017f57600080fd5b50610101600160a060020a0360043516610357565b3480156101a057600080fd5b50610101600160a060020a03600435166103b4565b3480156101c157600080fd5b506040805160206004803580820135601f81018490048402850184019095528484526101019436949293602493928401919081908401838280828437509497506104929650505050505050565b34801561021a57600080fd5b506102236104e9565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561025d578181015183820152602001610245565b50505050905090810190601f16801561028a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156102a457600080fd5b50610223610576565b600054600160a060020a031633146102c457600080fd5b80516102d79060029060208401906105ce565b506040517f15c0693e714f552c7a83e9adacc650edf641b7f02ed0addff6a555e6918d36c690600090a150565b600054600160a060020a0316331461031b57600080fd5b600054600160a060020a0316ff5b600354600160a060020a03165b90565b600354600160a060020a031681565b600054600160a060020a031681565b600054600160a060020a031633148061037a5750600454600160a060020a031633145b151561038557600080fd5b6004805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600454600090600160a060020a038381169116141561048e57506003805473ffffffffffffffffffffffffffffffffffffffff191633908117909155604080517fbb62cf220000000000000000000000000000000000000000000000000000000081529051829163bb62cf2291600480830192600092919082900301818387803b15801561044157600080fd5b505af1158015610455573d6000803e3d6000fd5b5050604051600160a060020a03851692507f50522c7af4430ad2fb94eafa5822bb37d002c3278ea05da94aed3dd477b1c6959150600090a25b5050565b600054600160a060020a031633146104a957600080fd5b80516104bc9060019060208401906105ce565b506040517f579d1198506d9238b88e8ae90b599aa3b8e84aeca6151deb26d9adc89541f31790600090a150565b60018054604080516020600284861615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561056e5780601f106105435761010080835404028352916020019161056e565b820191906000526020600020905b81548152906001019060200180831161055157829003601f168201915b505050505081565b6002805460408051602060018416156101000260001901909316849004601f8101849004840282018401909252818152929183018282801561056e5780601f106105435761010080835404028352916020019161056e565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061060f57805160ff191683800117855561063c565b8280016001018555821561063c579182015b8281111561063c578251825591602001919060010190610621565b5061064892915061064c565b5090565b61033691905b8082111561064857600081556001016106525600a165627a7a72305820eda9438391c70d619cd5e7c2af9c1671744ea5c985a854f510d1a27d9a89faf40029";
public static final String FUNC_SETPP = "setpp";
public static final String FUNC_KILL = "kill";
public static final String FUNC_GETBONDDEVICE = "getBondDevice";
public static final String FUNC_BINDED = "binded";
public static final String FUNC_OWNER = "owner";
public static final String FUNC_SETBUYER = "setBuyer";
public static final String FUNC_BINDREQ = "bindReq";
public static final String FUNC_SETDEVICEINFO = "setdeviceinfo";
public static final String FUNC_DEVICEINFO = "deviceInfo";
public static final String FUNC_PRIVACYPOLICY = "privacypolicy";
public static final Event INFOUPDATE_EVENT = new Event("InfoUpdate",
Arrays.<TypeReference<?>>asList());
;
public static final Event POLICYUPDATE_EVENT = new Event("policyUpdate",
Arrays.<TypeReference<?>>asList());
;
public static final Event RECEIVEBINDREQUEST_EVENT = new Event("receiveBindRequest",
Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true) {}));
;
@Deprecated
protected DeviceContract(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
protected DeviceContract(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
@Deprecated
protected DeviceContract(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
protected DeviceContract(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
}
public RemoteCall<TransactionReceipt> setpp(String pp) {
final Function function = new Function(
FUNC_SETPP,
Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(pp)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteCall<TransactionReceipt> kill() {
final Function function = new Function(
FUNC_KILL,
Arrays.<Type>asList(),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteCall<String> getBondDevice() {
final Function function = new Function(FUNC_GETBONDDEVICE,
Arrays.<Type>asList(),
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
return executeRemoteCallSingleValueReturn(function, String.class);
}
public RemoteCall<String> binded() {
final Function function = new Function(FUNC_BINDED,
Arrays.<Type>asList(),
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
return executeRemoteCallSingleValueReturn(function, String.class);
}
public RemoteCall<String> owner() {
final Function function = new Function(FUNC_OWNER,
Arrays.<Type>asList(),
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
return executeRemoteCallSingleValueReturn(function, String.class);
}
public RemoteCall<TransactionReceipt> setBuyer(String _buyer) {
final Function function = new Function(
FUNC_SETBUYER,
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_buyer)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteCall<TransactionReceipt> bindReq(String requester) {
final Function function = new Function(
FUNC_BINDREQ,
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(requester)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteCall<TransactionReceipt> setdeviceinfo(String info) {
final Function function = new Function(
FUNC_SETDEVICEINFO,
Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(info)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteCall<String> deviceInfo() {
final Function function = new Function(FUNC_DEVICEINFO,
Arrays.<Type>asList(),
Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
return executeRemoteCallSingleValueReturn(function, String.class);
}
public RemoteCall<String> privacypolicy() {
final Function function = new Function(FUNC_PRIVACYPOLICY,
Arrays.<Type>asList(),
Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
return executeRemoteCallSingleValueReturn(function, String.class);
}
public List<InfoUpdateEventResponse> getInfoUpdateEvents(TransactionReceipt transactionReceipt) {
List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(INFOUPDATE_EVENT, transactionReceipt);
ArrayList<InfoUpdateEventResponse> responses = new ArrayList<InfoUpdateEventResponse>(valueList.size());
for (Contract.EventValuesWithLog eventValues : valueList) {
InfoUpdateEventResponse typedResponse = new InfoUpdateEventResponse();
typedResponse.log = eventValues.getLog();
responses.add(typedResponse);
}
return responses;
}
public Flowable<InfoUpdateEventResponse> infoUpdateEventFlowable(EthFilter filter) {
return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, InfoUpdateEventResponse>() {
@Override
public InfoUpdateEventResponse apply(Log log) {
Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(INFOUPDATE_EVENT, log);
InfoUpdateEventResponse typedResponse = new InfoUpdateEventResponse();
typedResponse.log = log;
return typedResponse;
}
});
}
public Flowable<InfoUpdateEventResponse> infoUpdateEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
filter.addSingleTopic(EventEncoder.encode(INFOUPDATE_EVENT));
return infoUpdateEventFlowable(filter);
}
public List<PolicyUpdateEventResponse> getPolicyUpdateEvents(TransactionReceipt transactionReceipt) {
List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(POLICYUPDATE_EVENT, transactionReceipt);
ArrayList<PolicyUpdateEventResponse> responses = new ArrayList<PolicyUpdateEventResponse>(valueList.size());
for (Contract.EventValuesWithLog eventValues : valueList) {
PolicyUpdateEventResponse typedResponse = new PolicyUpdateEventResponse();
typedResponse.log = eventValues.getLog();
responses.add(typedResponse);
}
return responses;
}
public Flowable<PolicyUpdateEventResponse> policyUpdateEventFlowable(EthFilter filter) {
return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, PolicyUpdateEventResponse>() {
@Override
public PolicyUpdateEventResponse apply(Log log) {
Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(POLICYUPDATE_EVENT, log);
PolicyUpdateEventResponse typedResponse = new PolicyUpdateEventResponse();
typedResponse.log = log;
return typedResponse;
}
});
}
public Flowable<PolicyUpdateEventResponse> policyUpdateEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
filter.addSingleTopic(EventEncoder.encode(POLICYUPDATE_EVENT));
return policyUpdateEventFlowable(filter);
}
public List<ReceiveBindRequestEventResponse> getReceiveBindRequestEvents(TransactionReceipt transactionReceipt) {
List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(RECEIVEBINDREQUEST_EVENT, transactionReceipt);
ArrayList<ReceiveBindRequestEventResponse> responses = new ArrayList<ReceiveBindRequestEventResponse>(valueList.size());
for (Contract.EventValuesWithLog eventValues : valueList) {
ReceiveBindRequestEventResponse typedResponse = new ReceiveBindRequestEventResponse();
typedResponse.log = eventValues.getLog();
typedResponse.requester = (String) eventValues.getIndexedValues().get(0).getValue();
responses.add(typedResponse);
}
return responses;
}
public Flowable<ReceiveBindRequestEventResponse> receiveBindRequestEventFlowable(EthFilter filter) {
return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, ReceiveBindRequestEventResponse>() {
@Override
public ReceiveBindRequestEventResponse apply(Log log) {
Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(RECEIVEBINDREQUEST_EVENT, log);
ReceiveBindRequestEventResponse typedResponse = new ReceiveBindRequestEventResponse();
typedResponse.log = log;
typedResponse.requester = (String) eventValues.getIndexedValues().get(0).getValue();
return typedResponse;
}
});
}
public Flowable<ReceiveBindRequestEventResponse> receiveBindRequestEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
filter.addSingleTopic(EventEncoder.encode(RECEIVEBINDREQUEST_EVENT));
return receiveBindRequestEventFlowable(filter);
}
@Deprecated
public static DeviceContract load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return new DeviceContract(contractAddress, web3j, credentials, gasPrice, gasLimit);
}
@Deprecated
public static DeviceContract load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return new DeviceContract(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
public static DeviceContract load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
return new DeviceContract(contractAddress, web3j, credentials, contractGasProvider);
}
public static DeviceContract load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
return new DeviceContract(contractAddress, web3j, transactionManager, contractGasProvider);
}
public static RemoteCall<DeviceContract> deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
return deployRemoteCall(DeviceContract.class, web3j, credentials, contractGasProvider, BINARY, "");
}
@Deprecated
public static RemoteCall<DeviceContract> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return deployRemoteCall(DeviceContract.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
}
public static RemoteCall<DeviceContract> deploy(Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
return deployRemoteCall(DeviceContract.class, web3j, transactionManager, contractGasProvider, BINARY, "");
}
@Deprecated
public static RemoteCall<DeviceContract> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return deployRemoteCall(DeviceContract.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
}
public static class InfoUpdateEventResponse {
public Log log;
}
public static class PolicyUpdateEventResponse {
public Log log;
}
public static class ReceiveBindRequestEventResponse {
public Log log;
public String requester;
}
}
package edu.prlab.tyler.iotgateway.contract;
import io.reactivex.Flowable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.web3j.abi.EventEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Event;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.request.EthFilter;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;
import org.web3j.tx.gas.ContractGasProvider;
/**
* <p>Auto generated code.
* <p><strong>Do not modify!</strong>
* <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
* or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the
* <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
*
* <p>Generated with web3j version 4.2.0.
*/
public class GatewayContract extends Contract {
private static final String BINARY = "608060405234801561001057600080fd5b5060008054600160a060020a031916331781556001556103dd806100356000396000f30060806040526004361061006c5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663052c45568114610071578063303877bf146100945780635fa8724b146100c8578063b5474550146100e0578063bb62cf2214610107575b600080fd5b34801561007d57600080fd5b50610092600160a060020a036004351661011c565b005b3480156100a057600080fd5b506100ac600435610283565b60408051600160a060020a039092168252519081900360200190f35b3480156100d457600080fd5b506100926004356102d9565b3480156100ec57600080fd5b506100f561031e565b60408051918252519081900360200190f35b34801561011357600080fd5b50610092610324565b6000805481908190600160a060020a0316331461013857600080fd5b60019250600091505b60015482101561019557600082815260026020526040902054600160a060020a038581169116141561018a57600082815260026020526040902060019081018190559250610195565b600190910190610141565b600183151514156101ff57604080518082018252600160a060020a038681168252600160208084018281528254600090815260029092529490209251835473ffffffffffffffffffffffffffffffffffffffff191692169190911782559151908201558054810190555b5060008054604080517fa3f6774d000000000000000000000000000000000000000000000000000000008152600160a060020a039283166004820152905186939284169263a3f6774d926024808201939182900301818387803b15801561026557600080fd5b505af1158015610279573d6000803e3d6000fd5b5050505050505050565b6000600154821115610297575060006102d4565b60008281526002602081905260409091206001015414156102d05750600081815260026020526040902054600160a060020a03166102d4565b5060005b919050565b600054600160a060020a031633146102f057600080fd5b6000811015801561030357506001548111155b1561031b576000818152600260205260408120600101555b50565b60015481565b60005b60015481101561031b57600081815260026020526040902054600160a060020a03163314156103a957600081815260026020526040902060019081015414156103a9576000818152600260208190526040808320600101919091555133917f2e3c42cbe8d40e1905dccdfd129295bf0d4a7ee9d8e28fc582619541c0a0294f91a25b6001016103275600a165627a7a72305820273afc7c3ee3e470171301e48897c667293b777050ec35e34d519b7c1e4e340e0029";
public static final String FUNC_BINDREQUEST = "bindRequest";
public static final String FUNC_GETDEVICEADDRESS = "getDeviceAddress";
public static final String FUNC_REMOVEDEVICE = "removeDevice";
public static final String FUNC_NUMDEVICES = "numDevices";
public static final String FUNC_BINDRESPONSE = "bindResponse";
public static final Event RECEIVEBINDRESPONSE_EVENT = new Event("receiveBindResponse",
Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true) {}));
;
@Deprecated
protected GatewayContract(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
protected GatewayContract(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
@Deprecated
protected GatewayContract(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
protected GatewayContract(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
}
public RemoteCall<TransactionReceipt> bindRequest(String dm) {
final Function function = new Function(
FUNC_BINDREQUEST,
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(dm)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteCall<String> getDeviceAddress(BigInteger i) {
final Function function = new Function(FUNC_GETDEVICEADDRESS,
Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(i)),
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
return executeRemoteCallSingleValueReturn(function, String.class);
}
public RemoteCall<TransactionReceipt> removeDevice(BigInteger i) {
final Function function = new Function(
FUNC_REMOVEDEVICE,
Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(i)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteCall<BigInteger> numDevices() {
final Function function = new Function(FUNC_NUMDEVICES,
Arrays.<Type>asList(),
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}
public RemoteCall<TransactionReceipt> bindResponse() {
final Function function = new Function(
FUNC_BINDRESPONSE,
Arrays.<Type>asList(),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public List<ReceiveBindResponseEventResponse> getReceiveBindResponseEvents(TransactionReceipt transactionReceipt) {
List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(RECEIVEBINDRESPONSE_EVENT, transactionReceipt);
ArrayList<ReceiveBindResponseEventResponse> responses = new ArrayList<ReceiveBindResponseEventResponse>(valueList.size());
for (Contract.EventValuesWithLog eventValues : valueList) {
ReceiveBindResponseEventResponse typedResponse = new ReceiveBindResponseEventResponse();
typedResponse.log = eventValues.getLog();
typedResponse.dm = (String) eventValues.getIndexedValues().get(0).getValue();
responses.add(typedResponse);
}
return responses;
}
public Flowable<ReceiveBindResponseEventResponse> receiveBindResponseEventFlowable(EthFilter filter) {
return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, ReceiveBindResponseEventResponse>() {
@Override
public ReceiveBindResponseEventResponse apply(Log log) {
Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(RECEIVEBINDRESPONSE_EVENT, log);
ReceiveBindResponseEventResponse typedResponse = new ReceiveBindResponseEventResponse();
typedResponse.log = log;
typedResponse.dm = (String) eventValues.getIndexedValues().get(0).getValue();
return typedResponse;
}
});
}
public Flowable<ReceiveBindResponseEventResponse> receiveBindResponseEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
filter.addSingleTopic(EventEncoder.encode(RECEIVEBINDRESPONSE_EVENT));
return receiveBindResponseEventFlowable(filter);
}
@Deprecated
public static GatewayContract load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return new GatewayContract(contractAddress, web3j, credentials, gasPrice, gasLimit);
}
@Deprecated
public static GatewayContract load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return new GatewayContract(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
public static GatewayContract load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
return new GatewayContract(contractAddress, web3j, credentials, contractGasProvider);
}
public static GatewayContract load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
return new GatewayContract(contractAddress, web3j, transactionManager, contractGasProvider);
}
public static RemoteCall<GatewayContract> deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
return deployRemoteCall(GatewayContract.class, web3j, credentials, contractGasProvider, BINARY, "");
}
public static RemoteCall<GatewayContract> deploy(Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
return deployRemoteCall(GatewayContract.class, web3j, transactionManager, contractGasProvider, BINARY, "");
}
@Deprecated
public static RemoteCall<GatewayContract> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return deployRemoteCall(GatewayContract.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
}
@Deprecated
public static RemoteCall<GatewayContract> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return deployRemoteCall(GatewayContract.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
}
public static class ReceiveBindResponseEventResponse {
public Log log;
public String dm;
}
}
package edu.prlab.tyler.iotgateway.contract;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.runners.MethodSorters;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.core.methods.response.Web3ClientVersion;
import org.web3j.protocol.http.HttpService;
import org.web3j.quorum.Quorum;
import org.web3j.tx.ClientTransactionManager;
import org.web3j.tx.gas.ContractGasProvider;
import org.web3j.tx.gas.DefaultGasProvider;
import org.web3j.tx.gas.StaticGasProvider;
import java.math.BigInteger;
......@@ -16,23 +21,22 @@ import java.math.BigInteger;
@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
public class ContractTester {
private static final String rpcUrl = "http://localhost:22001";
private static final String rpcUrl = "http://localhost:22000";
private static final String privateKey = "7777777777777777777777777777777777777777777777777777777777777777";
// private static final String privateKey = "7777777777777777777777777777777777777777777777777777777777777777";
protected static final ContractGasProvider DEFAULT_GAS_PROVIDER = new StaticGasProvider(
private static final ContractGasProvider DEFAULT_GAS_PROVIDER = new StaticGasProvider(
BigInteger.ZERO,
BigInteger.valueOf(1000000000L)
DefaultGasProvider.GAS_LIMIT
);
@BeforeEach
public void setUp() {
@BeforeClass
public static void setUp() {
}
@Test
public void deployContract() throws Exception {
System.out.println("test start");
public void test1deployDeviceContract() throws Exception {
// Credentials credentials = Credentials.create(privateKey);
Quorum quorum = Quorum.build(new HttpService(rpcUrl));
Web3ClientVersion web3ClientVersion = quorum.web3ClientVersion().sendAsync().get();
......@@ -42,15 +46,34 @@ public class ContractTester {
String userAddress = quorum.ethAccounts().send().getAccounts().get(0);
System.out.println("User : " + userAddress);
// ClientTransactionManager manager = new ClientTransactionManager(quorum, userAddress);
// Credentials credentials = Credentials.create(privateKey);
ClientTransactionManager manager = new ClientTransactionManager(quorum, userAddress);
DeviceContract deviceContract = DeviceContract.deploy(quorum, manager, DEFAULT_GAS_PROVIDER).send();
String deviceContractAddress = deviceContract.getContractAddress();
System.out.println("智慧合約地址 : " + deviceContractAddress);
Assert.assertNotNull(deviceContract);
TransactionReceipt deviceReceipt = deviceContract.setdeviceinfo("testdevice").send();
System.out.println(deviceReceipt.toString());
TransactionReceipt privacyPolicyReceipt = deviceContract.setpp("testpp").send();
System.out.println(privacyPolicyReceipt.toString());
String deviceInfo = deviceContract.deviceInfo().send();
System.out.println(deviceInfo);
String privacyPolicy = deviceContract.privacypolicy().send();
System.out.println(privacyPolicy);
// DeviceContract deviceContract = DeviceContract.deploy(quorum, manager,DEFAULT_GAS_PROVIDER).send();
//
// System.out.println("智慧合約地址:" + deviceContract.getContractAddress());
//
// Assert.assertNotNull(deviceContract);
System.out.println("test end");
}
@Test
public void test2uploadDeviceInfoAndPolicy() throws Exception {}
@Test
public void test3deployGatewayContract() throws Exception {}
@Test
public void test4bind() throws Exception {}
}
......@@ -33,6 +33,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation project(":cloud")
implementation project(":contract")
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
......
......@@ -7,3 +7,6 @@ rootProject.name = 'gateway'
include ":cloud"
project(":cloud").projectDir = file("../cloud")
include ":contract"
project(":contract").projectDir = file("../contract")
\ No newline at end of file
package edu.prlab.tyler.iotgateway.gateway.controllers;
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.PrivacyPolicyReport;
import edu.prlab.tyler.iotgateway.gateway.services.PrivacyService;
......@@ -15,6 +16,12 @@ public class GatewayController {
this.privacyService = privacyService;
}
// TODO
// @GetMapping("")
// public ResponseEntity<Iterable<Device>> readDevicesOfUser() {
//
// }
@GetMapping("/privacy/{UDN}")
public ResponseEntity<PrivacyPolicyReport> readPrivacyPolicyReportByDevice(@PathVariable(value = "UDN") String UDN) {
return privacyService.getRelatedPrivacyPolicies(UDN)
......@@ -28,5 +35,4 @@ public class GatewayController {
.map(ResponseEntity::ok)
.orElseGet(()->ResponseEntity.noContent().build());
}
}
package edu.prlab.tyler.iotgateway.gateway.services;
import org.springframework.stereotype.Service;
@Service
public class DeviceService {
}
......@@ -14,13 +14,17 @@ public class PrivacyService {
private RestTemplate template;
@Value("${iotgateway.cloud.address}")
private String cloudAddress;
public PrivacyService() {
this.template = new RestTemplate();
}
@Value("${iotgateway.cloud.address}")
private void setCloudAddress(String cloudAddress) {
this.cloudAddress = cloudAddress;
}
public Optional<PrivacyPolicyReport> getRelatedPrivacyPolicies(String Udn) {
return Optional.ofNullable(template.getForObject(cloudAddress + "/device/privacy/" + Udn, PrivacyPolicyReport.class));
}
......
package edu.prlab.tyler.iotgateway.gateway;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.prlab.tyler.iotgateway.cloud.pojo.auth.User;
import edu.prlab.tyler.iotgateway.cloud.pojo.auth.SensitiveUser;
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.PrivacyContent;
......@@ -20,8 +20,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import java.math.BigInteger;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
......@@ -45,6 +43,10 @@ public class GatewayHttpApiTest {
@Test
public void getPrivacyPolicyAndSetChoice() throws Exception{
//取得裝置清單
//拿取隱私政策
MvcResult result = mvc.perform(MockMvcRequestBuilders
.get("/privacy/" + "a1252c49-4188-4e6d-a32e-66604c664fb8")
.accept(MediaType.APPLICATION_JSON_UTF8))
......@@ -52,25 +54,21 @@ public class GatewayHttpApiTest {
.andExpect(status().isOk())
.andReturn();
PrivacyPolicyReport report = mapper.readValue(result.getResponse().getContentAsString(), PrivacyPolicyReport.class);
Assert.assertNotNull(report);
//表達隱私偏好
Device device = report.getDevice();
PrivacyChoice privacyChoice = PrivacyChoice.builder()
.privacyContent(PrivacyContent.builder()
.user(User.builder()
.account("test")
.user(SensitiveUser.builder()
.username("test")
.password("test")
.publicKey(BigInteger.ONE)
.privateKey(BigInteger.ONE)
.address("test Address").build())
.build())
.device(device)
.policy(report.getPolicies().get(0))
.build())
.isAccepted(true)
.build();
mapper.writeValueAsString(privacyChoice);
result = mvc.perform(MockMvcRequestBuilders
.post("/choice")
......@@ -80,8 +78,6 @@ public class GatewayHttpApiTest {
.andDo(print())
.andExpect(status().isOk())
.andReturn();
Assert.assertNotNull(result);
}
}
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