71 lines
2.4 KiB
Java
71 lines
2.4 KiB
Java
package blockchain.query.User;
|
|
|
|
import blockchain.client.ChannelClientWrapper;
|
|
import blockchain.client.FabricClientWrapper;
|
|
import blockchain.configuration.Config;
|
|
import blockchain.query.QueryTest;
|
|
import blockchain.user.UserContext;
|
|
import blockchain.utility.Util;
|
|
import org.apache.log4j.BasicConfigurator;
|
|
import org.apache.log4j.Logger;
|
|
import org.hyperledger.fabric.sdk.ChaincodeResponse;
|
|
import org.hyperledger.fabric.sdk.ProposalResponse;
|
|
import org.junit.Ignore;
|
|
import org.junit.Test;
|
|
|
|
import javax.json.Json;
|
|
import javax.json.JsonObject;
|
|
import javax.json.JsonReader;
|
|
import java.io.StringReader;
|
|
import java.util.Collection;
|
|
|
|
@Ignore
|
|
public class ReadUserTest {
|
|
private static Logger logger = Logger.getLogger(QueryTest.class);
|
|
|
|
@Test
|
|
public void TestQueryReadUser() {
|
|
BasicConfigurator.configure();
|
|
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
|
|
try{
|
|
String chaincode = Config.CHAINCODE_NAME;
|
|
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
|
|
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
|
|
|
//String[] args1 = {"chef"}
|
|
//String[] args1 = {"bitman"};
|
|
//String[] args1 = {"foutre"};
|
|
String[] args1 = {"usera"};
|
|
|
|
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"readUser",args1);
|
|
logger.info("RESPONSE : "+responseQuery);
|
|
logger.info("RESPONSE : "+responseQuery.size());
|
|
|
|
String response = null;
|
|
|
|
for(ProposalResponse pres : responseQuery){
|
|
ChaincodeResponse.Status status = pres.getStatus();
|
|
|
|
if(status.getStatus()!=200){
|
|
throw new Exception(pres.getMessage());
|
|
}
|
|
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
|
response = stringResponse;
|
|
logger.info("RESPONSE : "+stringResponse);
|
|
}
|
|
|
|
JsonReader reader = Json.createReader(new StringReader(response));
|
|
JsonObject userInfo = reader.readObject();
|
|
logger.info("userAssociation : "+userInfo.getString("userAssociation"));
|
|
logger.info("userFirstName : "+userInfo.getString("userFirstName"));
|
|
|
|
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
}
|