@Test public void testReconstructChannel() throws ClassNotFoundException, SQLException, InvalidArgumentException, ProposalException, java.lang.Exception { PowerMockito.mockStatic(HFClient.class); when(HFClient.createNewInstance()).thenReturn(mockClient); Set<String> returnSet = new HashSet<String>(); returnSet.add("a"); returnSet.add("c"); when(mockClient.queryChannels(any(Peer.class))).thenReturn(returnSet); String configPath = "src/test/resources/blockchain-query"; Class.forName("com.impetus.fabric.jdbc.FabricDriver"); QueryBlock qb = new QueryBlock(configPath,"mychannel", null, null); HyperUser mockuser = mock(HyperUser.class); when(mockuser.isEnrolled()).thenReturn(true); Store mockStore = mock(Store.class); PowerMockito.whenNew(Store.class).withAnyArguments().thenReturn(mockStore); Channel mockChannel = mock(Channel.class); when(mockClient.newChannel(anyString())).thenReturn(mockChannel); qb.reconstructChannel(); }
public Channel reconstructChannel() { checkConfig(); try { org.apache.log4j.Level setTo = null; setTo = org.apache.log4j.Level.DEBUG; org.apache.log4j.Logger.getLogger("org.hyperledger.fabric").setLevel(setTo); Channel newChannel = null; client.setUserContext(user); newChannel = client.newChannel(channelName); for (String orderName : userOrg.getOrdererNames()) { newChannel.addOrderer(client.newOrderer(orderName, userOrg.getOrdererLocation(orderName), conf.getOrdererProperties(orderName))); } for (String peerName : userOrg.getPeerNames()) { logger.debug(peerName); String peerLocation = userOrg.getPeerLocation(peerName); Peer peer = client.newPeer(peerName, peerLocation, conf.getPeerProperties(peerName)); Set<String> channels = client.queryChannels(peer); if (!channels.contains(channelName)) { logger.info(String.format("Peer %s does not appear to belong to channel %s", peerName, channelName)); } newChannel.addPeer(peer); userOrg.addPeer(peer); } for (String eventHubName : userOrg.getEventHubNames()) { EventHub eventHub = client.newEventHub(eventHubName, userOrg.getEventHubLocation(eventHubName), conf.getEventHubProperties(eventHubName)); newChannel.addEventHub(eventHub); } newChannel.initialize(); return newChannel; } catch (Exception e) { String errMsg = "QueryBlock | reconstructChannel " + e; logger.error(errMsg); throw new BlkchnException(errMsg, e); } }
QueryBlock { public Channel reconstructChannel() { checkConfig(); try { org.apache.log4j.Level setTo = null; setTo = org.apache.log4j.Level.DEBUG; org.apache.log4j.Logger.getLogger("org.hyperledger.fabric").setLevel(setTo); Channel newChannel = null; client.setUserContext(user); newChannel = client.newChannel(channelName); for (String orderName : userOrg.getOrdererNames()) { newChannel.addOrderer(client.newOrderer(orderName, userOrg.getOrdererLocation(orderName), conf.getOrdererProperties(orderName))); } for (String peerName : userOrg.getPeerNames()) { logger.debug(peerName); String peerLocation = userOrg.getPeerLocation(peerName); Peer peer = client.newPeer(peerName, peerLocation, conf.getPeerProperties(peerName)); Set<String> channels = client.queryChannels(peer); if (!channels.contains(channelName)) { logger.info(String.format("Peer %s does not appear to belong to channel %s", peerName, channelName)); } newChannel.addPeer(peer); userOrg.addPeer(peer); } for (String eventHubName : userOrg.getEventHubNames()) { EventHub eventHub = client.newEventHub(eventHubName, userOrg.getEventHubLocation(eventHubName), conf.getEventHubProperties(eventHubName)); newChannel.addEventHub(eventHub); } newChannel.initialize(); return newChannel; } catch (Exception e) { String errMsg = "QueryBlock | reconstructChannel " + e; logger.error(errMsg); throw new BlkchnException(errMsg, e); } } }
QueryBlock { public Channel reconstructChannel() { checkConfig(); try { org.apache.log4j.Level setTo = null; setTo = org.apache.log4j.Level.DEBUG; org.apache.log4j.Logger.getLogger("org.hyperledger.fabric").setLevel(setTo); Channel newChannel = null; client.setUserContext(user); newChannel = client.newChannel(channelName); for (String orderName : userOrg.getOrdererNames()) { newChannel.addOrderer(client.newOrderer(orderName, userOrg.getOrdererLocation(orderName), conf.getOrdererProperties(orderName))); } for (String peerName : userOrg.getPeerNames()) { logger.debug(peerName); String peerLocation = userOrg.getPeerLocation(peerName); Peer peer = client.newPeer(peerName, peerLocation, conf.getPeerProperties(peerName)); Set<String> channels = client.queryChannels(peer); if (!channels.contains(channelName)) { logger.info(String.format("Peer %s does not appear to belong to channel %s", peerName, channelName)); } newChannel.addPeer(peer); userOrg.addPeer(peer); } for (String eventHubName : userOrg.getEventHubNames()) { EventHub eventHub = client.newEventHub(eventHubName, userOrg.getEventHubLocation(eventHubName), conf.getEventHubProperties(eventHubName)); newChannel.addEventHub(eventHub); } newChannel.initialize(); return newChannel; } catch (Exception e) { String errMsg = "QueryBlock | reconstructChannel " + e; logger.error(errMsg); throw new BlkchnException(errMsg, e); } } QueryBlock(String configPath, String channel, String username, String secret); }
QueryBlock { public Channel reconstructChannel() { checkConfig(); try { org.apache.log4j.Level setTo = null; setTo = org.apache.log4j.Level.DEBUG; org.apache.log4j.Logger.getLogger("org.hyperledger.fabric").setLevel(setTo); Channel newChannel = null; client.setUserContext(user); newChannel = client.newChannel(channelName); for (String orderName : userOrg.getOrdererNames()) { newChannel.addOrderer(client.newOrderer(orderName, userOrg.getOrdererLocation(orderName), conf.getOrdererProperties(orderName))); } for (String peerName : userOrg.getPeerNames()) { logger.debug(peerName); String peerLocation = userOrg.getPeerLocation(peerName); Peer peer = client.newPeer(peerName, peerLocation, conf.getPeerProperties(peerName)); Set<String> channels = client.queryChannels(peer); if (!channels.contains(channelName)) { logger.info(String.format("Peer %s does not appear to belong to channel %s", peerName, channelName)); } newChannel.addPeer(peer); userOrg.addPeer(peer); } for (String eventHubName : userOrg.getEventHubNames()) { EventHub eventHub = client.newEventHub(eventHubName, userOrg.getEventHubLocation(eventHubName), conf.getEventHubProperties(eventHubName)); newChannel.addEventHub(eventHub); } newChannel.initialize(); return newChannel; } catch (Exception e) { String errMsg = "QueryBlock | reconstructChannel " + e; logger.error(errMsg); throw new BlkchnException(errMsg, e); } } QueryBlock(String configPath, String channel, String username, String secret); Config getConf(); String getAdminName(); void setAdminName(String adminName); String getChannelName(); void setChannelName(String channelName); void setChannel(); Channel getChannel(); void checkConfig(); synchronized void registerUser(String uname, String secret, String affiliation); synchronized HyperUser enroll(); Channel reconstructChannel(); Channel reconstructChannel(List<Peer> peers, HFClient client); String installChaincode(String chaincodeName, String version, String goPath, String chaincodePath); String instantiateChaincode(String chaincodeName, String chainCodeVersion, String chainCodePath,
            String chaincodeFunction, String[] chaincodeArgs, Endorsers endorsers); DataFrame invokeChaincode(String chaincodename, String chaincodeFunction, String[] chaincodeArgs); String queryChaincode(String chaincodename, String chaincodeFunction, String[] chaincodeArgs); String upgradeChaincode(String chaincodeName, String chainCodeVersion, String chainCodePath,
            String chaincodeFunction, String[] chaincodeArgs, Endorsers endorsers); Long getChannelHeight(); }
QueryBlock { public Channel reconstructChannel() { checkConfig(); try { org.apache.log4j.Level setTo = null; setTo = org.apache.log4j.Level.DEBUG; org.apache.log4j.Logger.getLogger("org.hyperledger.fabric").setLevel(setTo); Channel newChannel = null; client.setUserContext(user); newChannel = client.newChannel(channelName); for (String orderName : userOrg.getOrdererNames()) { newChannel.addOrderer(client.newOrderer(orderName, userOrg.getOrdererLocation(orderName), conf.getOrdererProperties(orderName))); } for (String peerName : userOrg.getPeerNames()) { logger.debug(peerName); String peerLocation = userOrg.getPeerLocation(peerName); Peer peer = client.newPeer(peerName, peerLocation, conf.getPeerProperties(peerName)); Set<String> channels = client.queryChannels(peer); if (!channels.contains(channelName)) { logger.info(String.format("Peer %s does not appear to belong to channel %s", peerName, channelName)); } newChannel.addPeer(peer); userOrg.addPeer(peer); } for (String eventHubName : userOrg.getEventHubNames()) { EventHub eventHub = client.newEventHub(eventHubName, userOrg.getEventHubLocation(eventHubName), conf.getEventHubProperties(eventHubName)); newChannel.addEventHub(eventHub); } newChannel.initialize(); return newChannel; } catch (Exception e) { String errMsg = "QueryBlock | reconstructChannel " + e; logger.error(errMsg); throw new BlkchnException(errMsg, e); } } QueryBlock(String configPath, String channel, String username, String secret); Config getConf(); String getAdminName(); void setAdminName(String adminName); String getChannelName(); void setChannelName(String channelName); void setChannel(); Channel getChannel(); void checkConfig(); synchronized void registerUser(String uname, String secret, String affiliation); synchronized HyperUser enroll(); Channel reconstructChannel(); Channel reconstructChannel(List<Peer> peers, HFClient client); String installChaincode(String chaincodeName, String version, String goPath, String chaincodePath); String instantiateChaincode(String chaincodeName, String chainCodeVersion, String chainCodePath,
            String chaincodeFunction, String[] chaincodeArgs, Endorsers endorsers); DataFrame invokeChaincode(String chaincodename, String chaincodeFunction, String[] chaincodeArgs); String queryChaincode(String chaincodename, String chaincodeFunction, String[] chaincodeArgs); String upgradeChaincode(String chaincodeName, String chainCodeVersion, String chainCodePath,
            String chaincodeFunction, String[] chaincodeArgs, Endorsers endorsers); Long getChannelHeight();  }