Merge branch 'features/queryChannel' into develop
This commit is contained in:
commit
8222a0220a
Binary file not shown.
Binary file not shown.
|
@ -36,7 +36,7 @@ public class FabricClientWrapper {
|
|||
public Set<String> queryForChannels() throws InvalidArgumentException, IllegalArgumentException, ProposalException {
|
||||
client.newChannel(Config.CHANNEL_NAME);
|
||||
client.newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
Peer peer = client.newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
Peer peer = client.newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
|
||||
return client.queryChannels(peer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,41 +2,47 @@ package blockchain.configuration;
|
|||
|
||||
public class Config {
|
||||
|
||||
//ORGANIZATION
|
||||
public static final String ORG1_MSP = "Org1MSP";
|
||||
|
||||
public static final String ORG1 = "Org1";
|
||||
public static final String ORG1 = "org1";
|
||||
|
||||
//ADMIN
|
||||
public static final String ADMIN = "admin";
|
||||
|
||||
public static final String ADMIN_PASSWORD = "adminpw";
|
||||
|
||||
//CA
|
||||
public static final String CA_ORG1_URL = "http://vps577432.ovh.net:7054";
|
||||
|
||||
//ORDERER
|
||||
public static final String ORDERER_URL = "grpc://vps577432.ovh.net:7050";
|
||||
|
||||
public static final String ORDERER_NAME = "orderer.example.com";
|
||||
|
||||
public static final String CHANNEL_NAME = "mychannel_mycc";
|
||||
//CHANNEL - CHAINCODE
|
||||
public static final String CHANNEL_NAME = "mychannel";
|
||||
|
||||
public static final String CHAINCODE_NAME = "mycc";
|
||||
|
||||
//PEER 0
|
||||
public static final String ORG1_PEER_0 = "peer0.org1.example.com";
|
||||
|
||||
public static final String ORG1_PEER_0_URL = "grpc://vps577432.ovh.net:8051";
|
||||
|
||||
public static final String USER_TEST_SECRET = "frwcKfCYPxWA";
|
||||
//PEER 1
|
||||
public static final String ORG_PEER = "peer1.org1.example.com";
|
||||
|
||||
//TEST
|
||||
public static final String ORG_PEER_URL = "grpc://vps592802.ovh.net:9051";
|
||||
|
||||
//EVENTHUB
|
||||
public static final String ORG_PEER_EVENT_URL = "grpc://vps592802.ovh.net:9053";
|
||||
|
||||
//ADMIN FILE TEST
|
||||
public static final String ADMIN_FILE_PATH = "msp/AdminFiles";
|
||||
|
||||
public static final String ADMIN_KEY_PATH = ADMIN_FILE_PATH+"/keystore";
|
||||
|
||||
public static final String ADMIN_CERT_PATH = ADMIN_FILE_PATH+"/admincerts";
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ public class TestEnrollAdmin {
|
|||
assertEquals(Config.ORG1, verifyUser.getAffiliation());
|
||||
assertEquals(Config.ORG1_MSP, verifyUser.getMspId());
|
||||
|
||||
//ENROLL AND WRITE ADMIN
|
||||
adminContext = caClientWrapper.enrollAdmin(adminContext.getName(),Config.ADMIN_PASSWORD,adminContext.getAffiliation());
|
||||
|
||||
//Check Admin Enrollement
|
||||
|
|
|
@ -18,7 +18,7 @@ public class TestRegisterEnrollUser {
|
|||
caClientWrapper.setAdminContext(admin);
|
||||
UserContext userContext = new UserContext();
|
||||
|
||||
userContext.setName("UserJavaTest");
|
||||
userContext.setName("User-org1");
|
||||
userContext.setAffiliation(Config.ORG1);
|
||||
userContext.setMspId(Config.ORG1_MSP);
|
||||
String userSecret = caClientWrapper.registerUser(userContext.getName(),userContext.getAffiliation());
|
||||
|
|
33
src/test/java/blockchain/query/QueryChannelTest.java
Normal file
33
src/test/java/blockchain/query/QueryChannelTest.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package blockchain.query;
|
||||
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.hyperledger.fabric.sdk.Peer;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class QueryChannelTest {
|
||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
||||
|
||||
@Test
|
||||
public void testQ(){
|
||||
BasicConfigurator.configure();
|
||||
UserContext userContext = Util.readUserContext(Config.ORG1,"User-org1");
|
||||
|
||||
try{
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(userContext);
|
||||
Set<String> channels = fabricClientWrapper.queryForChannels();
|
||||
|
||||
logger.info("CHANNELS : "+channels);
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -22,40 +22,38 @@ public class QueryTest {
|
|||
BasicConfigurator.configure();
|
||||
|
||||
//UserContext admin = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
||||
UserContext user = Util.readUserContext(Config.ORG1,"User-org1");
|
||||
|
||||
try{
|
||||
|
||||
//TEST FAILED
|
||||
|
||||
UserContext admin = new UserContext();
|
||||
File pkFolder = new File(Config.ADMIN_KEY_PATH);
|
||||
File[] pkFile = pkFolder.listFiles();
|
||||
File certFolder = new File(Config.ADMIN_CERT_PATH);
|
||||
File[] certFile = certFolder.listFiles();
|
||||
admin.setName(Config.ADMIN);
|
||||
admin.setMspId(Config.ORG1_MSP);
|
||||
admin.setAffiliation(Config.ORG1);
|
||||
Enrollment enrollAdmin = Util.getEnrollement(Config.ADMIN_KEY_PATH, pkFile[0].getName(), Config.ADMIN_CERT_PATH, certFile[0].getName());
|
||||
admin.setEnrollment(enrollAdmin);
|
||||
|
||||
//UserContext admin = new UserContext();
|
||||
//File pkFolder = new File(Config.ADMIN_KEY_PATH);
|
||||
//File[] pkFile = pkFolder.listFiles();
|
||||
//File certFolder = new File(Config.ADMIN_CERT_PATH);
|
||||
//File[] certFile = certFolder.listFiles();
|
||||
//admin.setName(Config.ADMIN);
|
||||
//admin.setMspId(Config.ORG1_MSP);
|
||||
//admin.setAffiliation(Config.ORG1);
|
||||
//Enrollment enrollAdmin = Util.getEnrollement(Config.ADMIN_KEY_PATH, pkFile[0].getName(), Config.ADMIN_CERT_PATH, certFile[0].getName());
|
||||
//admin.setEnrollment(enrollAdmin);
|
||||
//END TEST
|
||||
|
||||
String chaincode = Config.CHAINCODE_NAME;
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(admin);
|
||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
||||
|
||||
Channel channel = channelClientWrapper.getChannel();
|
||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
//Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG_PEER_URL);
|
||||
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps577432.ovh.net:8053");
|
||||
//EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", Config.ORG_PEER_EVENT_URL);
|
||||
//Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
|
||||
//EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps577432.ovh.net:8053");
|
||||
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", Config.ORG_PEER_EVENT_URL);
|
||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
channel.addPeer(peer);
|
||||
channel.addEventHub(eventHub);
|
||||
channel.addOrderer(orderer);
|
||||
channel.initialize();
|
||||
|
||||
|
||||
String[] args1 = {"a"};
|
||||
|
||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"query",args1);
|
||||
|
@ -68,11 +66,8 @@ public class QueryTest {
|
|||
logger.info("RESPONSE : "+stringResponse);
|
||||
}
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
21
src/test/java/blockchain/utility/ReadUserTest.java
Normal file
21
src/test/java/blockchain/utility/ReadUserTest.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package blockchain.utility;
|
||||
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ReadUserTest {
|
||||
@Test
|
||||
public void testReadUserOrg1(){
|
||||
try{
|
||||
UserContext userContext = Util.readUserContext(Config.ORG1, "User-org1");
|
||||
System.out.println(userContext.getAffiliation());
|
||||
System.out.println(userContext.getMspId());
|
||||
System.out.println(userContext.getEnrollment().getCert());
|
||||
System.out.println(userContext.getEnrollment().getKey());
|
||||
System.out.println(userContext.getName());
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
target/test-classes/blockchain/query/QueryChannelTest.class
Normal file
BIN
target/test-classes/blockchain/query/QueryChannelTest.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
target/test-classes/blockchain/utility/ReadUserTest.class
Normal file
BIN
target/test-classes/blockchain/utility/ReadUserTest.class
Normal file
Binary file not shown.
Loading…
Reference in a new issue