Update features
This commit is contained in:
parent
57cd29ad6f
commit
4bd2b8d0da
Binary file not shown.
|
@ -41,9 +41,9 @@ dependencies {
|
||||||
exclude group:'log4j', module:'log4j'
|
exclude group:'log4j', module:'log4j'
|
||||||
}
|
}
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
androidTestImplementation 'com.android.support.test:runner:1.0.1'
|
||||||
androidTestImplementation 'com.android.support.test:rules:1.0.2'
|
androidTestImplementation 'com.android.support.test:rules:1.0.1'
|
||||||
androidTestImplementation 'com.android.support:support-annotations:28.0.0'
|
androidTestImplementation 'com.android.support:support-annotations:26.1.0'
|
||||||
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
|
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
|
||||||
exclude group: 'com.android.support', module: 'support-annotations'
|
exclude group: 'com.android.support', module: 'support-annotations'
|
||||||
})
|
})
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class LearningTest {
|
||||||
System.out.println(appContext.getPackageName());
|
System.out.println(appContext.getPackageName());
|
||||||
|
|
||||||
InputStream is = appContext.getResources().openRawResource(R.raw.config);
|
InputStream is = appContext.getResources().openRawResource(R.raw.config);
|
||||||
|
/*
|
||||||
try (JsonReader reader = Json.createReader(is)) {
|
try (JsonReader reader = Json.createReader(is)) {
|
||||||
JsonObject jsonConfig = (JsonObject) reader.read();
|
JsonObject jsonConfig = (JsonObject) reader.read();
|
||||||
System.out.println(jsonConfig);
|
System.out.println(jsonConfig);
|
||||||
|
@ -42,7 +42,7 @@ public class LearningTest {
|
||||||
NetworkConfig config;
|
NetworkConfig config;
|
||||||
config = NetworkConfig.fromJsonObject(jsonConfig);
|
config = NetworkConfig.fromJsonObject(jsonConfig);
|
||||||
//System.out.println(config!=null);
|
//System.out.println(config!=null);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Writer writer = new StringWriter();
|
Writer writer = new StringWriter();
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package monnethic.mobile.test.blockchain;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.test.InstrumentationRegistry;
|
||||||
|
|
||||||
|
import org.hyperledger.fabric.sdk.ProposalResponse;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import monnethic.mobile.blockchain.client.CAClientWrapper;
|
||||||
|
import monnethic.mobile.blockchain.client.ChannelClientWrapper;
|
||||||
|
import monnethic.mobile.blockchain.client.FabriClientWrapper;
|
||||||
|
import monnethic.mobile.blockchain.network.Config;
|
||||||
|
import monnethic.mobile.blockchain.participant.UserContext;
|
||||||
|
import monnethic.mobile.test.blockchain.Utility.UtilTest;
|
||||||
|
|
||||||
|
|
||||||
|
public class TestQuery {
|
||||||
|
@Test
|
||||||
|
public void TestAQueryChainCode() throws Exception {
|
||||||
|
// Test query for user a on blockchain
|
||||||
|
try{
|
||||||
|
String query = "query";
|
||||||
|
String[] args1 = {"a"};
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
|
||||||
|
String caUrl = Config.CA_ORG1_URL;
|
||||||
|
CAClientWrapper caClientWrapper = new CAClientWrapper(caUrl,null,null,null);
|
||||||
|
|
||||||
|
UserContext adminContext = new UserContext();
|
||||||
|
adminContext.setName(Config.ADMIN);
|
||||||
|
adminContext.setAffiliation(Config.ORG1);
|
||||||
|
adminContext.setMspId(Config.ORG1_MSP);
|
||||||
|
|
||||||
|
caClientWrapper.setAdminContext(adminContext);
|
||||||
|
adminContext = caClientWrapper.enrollAdmin(appContext,Config.ADMIN,Config.ADMIN_PASSWORD,Config.ORG1);
|
||||||
|
|
||||||
|
FabriClientWrapper fabriClientWrapper = new FabriClientWrapper(adminContext);
|
||||||
|
ChannelClientWrapper channelClientWrapper = fabriClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
||||||
|
|
||||||
|
Logger.getLogger(TestQuery.class.getName()).log(Level.INFO, "Querying for USER A ...");
|
||||||
|
|
||||||
|
Collection<ProposalResponse> responsesQuery = channelClientWrapper.queryByChainCode(Config.CHAINCODE_NAME,query,args1);
|
||||||
|
|
||||||
|
for(ProposalResponse pres : responsesQuery){
|
||||||
|
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
||||||
|
Logger.getLogger(TestQuery.class.getName()).log(Level.INFO, stringResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package monnethic.mobile.test.blockchain.Utility;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.test.InstrumentationRegistry;
|
||||||
|
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
|
import monnethic.mobile.blockchain.participant.UserContext;
|
||||||
|
import monnethic.mobile.blockchain.utility.Util;
|
||||||
|
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class UtilTest {
|
||||||
|
/*
|
||||||
|
@Test
|
||||||
|
public void readEmptyUserContext() throws Exception {
|
||||||
|
// Context of the app under test.
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAreadNonUserContext() throws Exception {
|
||||||
|
// Context of the app under test.
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
UserContext uc = Util.readUserContext(appContext,"tata","abdel");
|
||||||
|
if(uc!=null){
|
||||||
|
Logger.getLogger(UtilTest.class.getName()).log(Level.INFO, "UserContext is : "+uc.toString());
|
||||||
|
}else{
|
||||||
|
Logger.getLogger(UtilTest.class.getName()).log(Level.INFO, "UserContext doesn't exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBwriteUserContext() throws Exception {
|
||||||
|
// Context of the app under test.
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
UserContext user = new UserContext();
|
||||||
|
user.setName("abdel");
|
||||||
|
user.setAffiliation("toto");
|
||||||
|
user.setEnrollment(null);
|
||||||
|
user.setMspId("test");
|
||||||
|
|
||||||
|
Util.writeUserContext(appContext, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreadUserContext() throws Exception {
|
||||||
|
// Context of the app under test.
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
UserContext uc = Util.readUserContext(appContext,"toto","abdel");
|
||||||
|
Logger.getLogger(UtilTest.class.getName()).log(Level.INFO, "UserContext is : "+uc.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,8 +7,8 @@
|
||||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||||
<uses-permission android:name="android.permission.READ_PROFILE" />
|
<uses-permission android:name="android.permission.READ_PROFILE" />
|
||||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
|
|
|
@ -3,9 +3,14 @@ package monnethic.mobile.blockchain.client;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.hyperledger.fabric.sdk.Enrollment;
|
import org.hyperledger.fabric.sdk.Enrollment;
|
||||||
|
import org.hyperledger.fabric.sdk.exception.CryptoException;
|
||||||
|
import org.hyperledger.fabric.sdk.security.CryptoSuite;
|
||||||
import org.hyperledger.fabric_ca.sdk.HFCAClient;
|
import org.hyperledger.fabric_ca.sdk.HFCAClient;
|
||||||
import org.hyperledger.fabric_ca.sdk.RegistrationRequest;
|
import org.hyperledger.fabric_ca.sdk.RegistrationRequest;
|
||||||
|
import org.hyperledger.fabric.sdk.exception.InvalidArgumentException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@ -14,44 +19,76 @@ import monnethic.mobile.blockchain.utility.Util;
|
||||||
|
|
||||||
public class CAClientWrapper {
|
public class CAClientWrapper {
|
||||||
|
|
||||||
|
private String caUrl;
|
||||||
private HFCAClient hfcaClient;
|
private HFCAClient hfcaClient;
|
||||||
|
private Properties properties;
|
||||||
private String org;
|
private String org;
|
||||||
private String url = "http://ca.org1.example.com:7054";
|
private String mspId;
|
||||||
private String mspId = "";
|
private UserContext adminContext;
|
||||||
|
|
||||||
|
public UserContext getAdminContext() {
|
||||||
|
return adminContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAdminContext(UserContext adminContext){
|
||||||
|
this.adminContext=adminContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public CAClientWrapper(String caUrl, Properties properties, String org, String mspId) throws MalformedURLException, IllegalAccessException, InstantiationException, ClassNotFoundException, CryptoException, InvalidArgumentException, NoSuchMethodException, InvocationTargetException {
|
||||||
|
this.caUrl=caUrl;
|
||||||
|
this.properties=properties;
|
||||||
|
this.org=org;
|
||||||
|
this.mspId=mspId;
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() throws MalformedURLException, IllegalAccessException, InstantiationException, ClassNotFoundException, CryptoException, InvalidArgumentException, NoSuchMethodException, InvocationTargetException {
|
||||||
|
CryptoSuite cryptoSuite = CryptoSuite.Factory.getCryptoSuite();
|
||||||
|
hfcaClient = HFCAClient.createNewInstance(caUrl,properties);
|
||||||
|
hfcaClient.setCryptoSuite(cryptoSuite);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HFCAClient getHfcaClient(){
|
||||||
|
return hfcaClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public CAClientWrapper(String url, String org){
|
public CAClientWrapper(String url, String org){
|
||||||
this.org=org;
|
this.org=org;
|
||||||
init(url);
|
init(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(String url){
|
private void init(String url){
|
||||||
try{
|
try{
|
||||||
this.hfcaClient = HFCAClient.createNewInstance(url,null);
|
this.hfcaClient = HFCAClient.createNewInstance(url,null);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
//Method to enroll admin
|
|
||||||
public void enrollAdmin(Context context, String name, String secret, String org) throws Exception {
|
//Method to enroll admin and save his info
|
||||||
|
public UserContext enrollAdmin(Context context, String name, String secret, String org) throws Exception {
|
||||||
UserContext adminContext;
|
UserContext adminContext;
|
||||||
adminContext = Util.readUserContext(context,name,secret);
|
adminContext = Util.readUserContext(context,name,secret);
|
||||||
if(adminContext!=null){
|
if(adminContext!=null){
|
||||||
Logger.getLogger(CAClientWrapper.class.getName()).log(Level.WARNING, "Admin already enrolled, skip");
|
Logger.getLogger(CAClientWrapper.class.getName()).log(Level.WARNING, "Admin already enrolled, skip");
|
||||||
return;
|
return adminContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
Enrollment enrollment = hfcaClient.enroll(name,secret);
|
Enrollment enrollment = hfcaClient.enroll(name,secret);
|
||||||
Logger.getLogger(CAClientWrapper.class.getName()).log(Level.INFO, "Admin enrolled");
|
Logger.getLogger(CAClientWrapper.class.getName()).log(Level.INFO, "Admin enrolled");
|
||||||
|
|
||||||
adminContext = new UserContext();
|
//adminContext = new UserContext();
|
||||||
adminContext.setName(name);
|
//adminContext.setName(name);
|
||||||
|
//adminContext.setAffiliation(org);
|
||||||
|
//adminContext.setMspId(mspId);
|
||||||
adminContext.setEnrollment(enrollment);
|
adminContext.setEnrollment(enrollment);
|
||||||
adminContext.setAffiliation(org);
|
|
||||||
adminContext.setMspId(mspId);
|
|
||||||
|
|
||||||
Util.writeUserContext(context,adminContext);
|
Util.writeUserContext(context,adminContext);
|
||||||
|
return adminContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Method to register and enroll user
|
//Method to register and enroll user
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package monnethic.mobile.blockchain.client;
|
||||||
|
|
||||||
|
import org.hyperledger.fabric.sdk.ChaincodeID;
|
||||||
|
import org.hyperledger.fabric.sdk.Channel;
|
||||||
|
import org.hyperledger.fabric.sdk.ProposalResponse;
|
||||||
|
import org.hyperledger.fabric.sdk.QueryByChaincodeRequest;
|
||||||
|
import org.hyperledger.fabric.sdk.exception.InvalidArgumentException;
|
||||||
|
import org.hyperledger.fabric.sdk.exception.ProposalException;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class ChannelClientWrapper {
|
||||||
|
FabriClientWrapper fabriClientWrapper;
|
||||||
|
Channel channel;
|
||||||
|
String name;
|
||||||
|
|
||||||
|
public Channel getChannel() {
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FabriClientWrapper getFabriClientWrapper() {
|
||||||
|
return fabriClientWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChannelClientWrapper(String name, Channel channel, FabriClientWrapper fabriClientWrapper){
|
||||||
|
this.name=name;
|
||||||
|
this.channel=channel;
|
||||||
|
this.fabriClientWrapper=fabriClientWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<ProposalResponse> queryByChainCode(String chaincodeName, String functionName, String[] args) throws InvalidArgumentException, ProposalException {
|
||||||
|
Logger.getLogger(ChannelClientWrapper.class.getName()).log(Level.INFO, "Querying "+chaincodeName+" with "+functionName);
|
||||||
|
|
||||||
|
QueryByChaincodeRequest request = fabriClientWrapper.getHfClient().newQueryProposalRequest();
|
||||||
|
ChaincodeID chaincodeId = ChaincodeID.newBuilder().setName(chaincodeName).build();
|
||||||
|
request.setChaincodeID(chaincodeId);
|
||||||
|
request.setFcn(functionName);
|
||||||
|
|
||||||
|
if(args != null){
|
||||||
|
request.setArgs(args);
|
||||||
|
}
|
||||||
|
Collection<ProposalResponse> response = channel.queryByChaincode(request);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package monnethic.mobile.blockchain.client;
|
||||||
|
|
||||||
|
import org.hyperledger.fabric.sdk.Channel;
|
||||||
|
import org.hyperledger.fabric.sdk.HFClient;
|
||||||
|
import org.hyperledger.fabric.sdk.exception.CryptoException;
|
||||||
|
import org.hyperledger.fabric.sdk.exception.InvalidArgumentException;
|
||||||
|
import org.hyperledger.fabric.sdk.security.CryptoSuite;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
|
import monnethic.mobile.blockchain.participant.UserContext;
|
||||||
|
|
||||||
|
public class FabriClientWrapper {
|
||||||
|
private HFClient hfClient;
|
||||||
|
|
||||||
|
public HFClient getHfClient() {
|
||||||
|
return hfClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FabriClientWrapper(UserContext userContext) throws CryptoException, InvalidArgumentException, IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException {
|
||||||
|
CryptoSuite cryptoSuite = CryptoSuite.Factory.getCryptoSuite();
|
||||||
|
hfClient = HFClient.createNewInstance();
|
||||||
|
hfClient.setCryptoSuite(cryptoSuite);
|
||||||
|
hfClient.setUserContext(userContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChannelClientWrapper createChannelClient(String name) throws InvalidArgumentException {
|
||||||
|
Channel channel = hfClient.newChannel(name);
|
||||||
|
ChannelClientWrapper client = new ChannelClientWrapper(name, channel, this);
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package monnethic.mobile.blockchain.network;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
//TODO SET STATIC FINAL VAR FOR NETWORK CONFIG, REPLACE LOADCONFIGINFO
|
||||||
|
public static final String ORG1_MSP = "Org1MSP";
|
||||||
|
|
||||||
|
public static final String ORG1 = "org1";
|
||||||
|
|
||||||
|
public static final String ADMIN = "AdminOrg1";
|
||||||
|
|
||||||
|
public static final String ADMIN_PASSWORD = "AdminOrg1Pwd";
|
||||||
|
|
||||||
|
public static final String CA_ORG1_URL = "vps577432.ovh.net:7054";
|
||||||
|
|
||||||
|
public static final String ORDERER_URL = "vps577432.ovh.net:7050";
|
||||||
|
|
||||||
|
public static final String ORDERER_NAME = "orderer.example.com";
|
||||||
|
|
||||||
|
public static final String CHANNEL_NAME = "mychannel";
|
||||||
|
|
||||||
|
public static final String CHAINCODE_NAME = "mycc";
|
||||||
|
|
||||||
|
public static final String ORG1_PEER_0 = "peer0.org1.example.com";
|
||||||
|
|
||||||
|
public static final String ORG1_PEER_0_URL = "vps577432.ovh.net:7051";
|
||||||
|
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ public class UserContext implements User, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
protected String name;
|
protected String name;
|
||||||
protected Set<String> roles;
|
protected Set<String> roles;
|
||||||
protected String account;
|
protected String account;
|
||||||
protected String affiliation;
|
protected String affiliation;
|
||||||
protected Enrollment enrollment;
|
protected Enrollment enrollment;
|
||||||
|
@ -45,7 +45,7 @@ public class UserContext implements User, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAffiliation() {
|
public String getAffiliation() {
|
||||||
return null;
|
return affiliation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAffiliation(String affiliation){
|
public void setAffiliation(String affiliation){
|
||||||
|
|
|
@ -7,6 +7,8 @@ import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import monnethic.mobile.blockchain.participant.UserContext;
|
import monnethic.mobile.blockchain.participant.UserContext;
|
||||||
|
|
||||||
|
@ -21,21 +23,26 @@ public class Util {
|
||||||
//Method which write user info into a directory
|
//Method which write user info into a directory
|
||||||
public static void writeUserContext(Context context, UserContext userContext){
|
public static void writeUserContext(Context context, UserContext userContext){
|
||||||
ObjectOutputStream out = null;
|
ObjectOutputStream out = null;
|
||||||
FileOutputStream file = null;
|
FileOutputStream fileOutputStream = null;
|
||||||
try{
|
try{
|
||||||
String filename = userContext.getName()+".context";
|
String filename = userContext.getName()+".context";
|
||||||
String dirPath = context.getFilesDir()+"userInfos/"+userContext.getAffiliation();
|
String dirPath = context.getFilesDir()+"userInfos/"+userContext.getAffiliation();
|
||||||
String pathFile = dirPath+"/"+filename;
|
String pathFile = dirPath+"/"+filename;
|
||||||
|
Logger.getLogger(Util.class.getName()).log(Level.INFO, "pathFile is : "+pathFile);
|
||||||
File dir = new File(dirPath);
|
File dir = new File(dirPath);
|
||||||
if(!dir.exists()){
|
if(!dir.exists()){
|
||||||
dir.mkdirs();
|
Boolean res = dir.mkdirs();
|
||||||
|
if(res){
|
||||||
|
Logger.getLogger(Util.class.getName()).log(Level.INFO, "RESPONSE IS TRUE");
|
||||||
|
}else{
|
||||||
|
Logger.getLogger(Util.class.getName()).log(Level.SEVERE, "RESPONSE IS FALSE");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file = null;
|
File file = new File(pathFile);
|
||||||
file = new FileOutputStream(pathFile);
|
fileOutputStream = new FileOutputStream(file);
|
||||||
out = new ObjectOutputStream(file);
|
out = new ObjectOutputStream(fileOutputStream);
|
||||||
|
Logger.getLogger(Util.class.getName()).log(Level.INFO, "out is : "+out);
|
||||||
out.writeObject(userContext);
|
out.writeObject(userContext);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -48,8 +55,8 @@ public class Util {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
if(file != null){
|
if(fileOutputStream != null){
|
||||||
file.close();
|
fileOutputStream.close();
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package monnethic.mobile.test.blockchain;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
import monnethic.mobile.blockchain.client.CAClientWrapper;
|
||||||
|
import monnethic.mobile.blockchain.network.Config;
|
||||||
|
import monnethic.mobile.blockchain.participant.UserContext;
|
||||||
|
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class TestQuery {
|
||||||
|
@Test
|
||||||
|
void TestAQueryChainCode(){
|
||||||
|
try{
|
||||||
|
//context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
|
||||||
|
String caUrl = Config.CA_ORG1_URL;
|
||||||
|
CAClientWrapper caClientWrapper = new CAClientWrapper(caUrl,null,null,null);
|
||||||
|
|
||||||
|
UserContext adminContext = new UserContext();
|
||||||
|
adminContext.setName(Config.ADMIN);
|
||||||
|
adminContext.setAffiliation(Config.ORG1);
|
||||||
|
adminContext.setMspId(Config.ORG1_MSP);
|
||||||
|
|
||||||
|
caClientWrapper.setAdminContext(adminContext);
|
||||||
|
//adminContext = caClientWrapper.enrollAdmin(appContext);
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue