public static PrimitiveStatement<?> getStatement(Class<?> clazz, TestCase tc) throws IllegalArgumentException{ if(!isEnvironmentData(clazz)){ throw new IllegalArgumentException("Class "+clazz.getName()+" is not an environment data type"); } if(clazz.equals(EvoSuiteFile.class)){ return new FileNamePrimitiveStatement(tc, new EvoSuiteFile(Randomness.choice(tc.getAccessedEnvironment().getViewOfAccessedFiles()))); } else if(clazz.equals(EvoSuiteLocalAddress.class)){ return new LocalAddressPrimitiveStatement(tc); } else if(clazz.equals(EvoSuiteRemoteAddress.class)){ return new RemoteAddressPrimitiveStatement(tc); } else if(clazz.equals(EvoSuiteURL.class)){ return new UrlPrimitiveStatement(tc); } else if(clazz.equals(EvoName.class)){ return new NamePrimitiveStatement(tc); } throw new RuntimeException("EvoSuite bug: unhandled class "+clazz.getName()); } }
private void handleVirtualFS(TestCase test) { test.getAccessedEnvironment().addLocalFiles(VirtualFileSystem.getInstance().getAccessedFiles()); if (!hasAddedFiles && VirtualFileSystem.getInstance().getAccessedFiles().size() > 0) { logger.info("Adding EvoSuiteFile calls to cluster"); hasAddedFiles = true; addEnvironmentClassToCluster(FileSystemHandling.class); } }
/** {@inheritDoc} */ @Override public void randomize() { String path = Randomness.choice(tc.getAccessedEnvironment().getViewOfAccessedFiles()); if (path != null) { setValue(new EvoSuiteFile(path)); } else { setValue(null); // FIXME find out why this case can actually happen! (I don't think we want this?) } logger.debug("Randomized filename: " + value); }
@Override public void randomize() { EvoSuiteLocalAddress addr; if(!tc.getAccessedEnvironment().getViewOfLocalListeningPorts().isEmpty()){ EndPointInfo info = Randomness.choice(tc.getAccessedEnvironment().getViewOfLocalListeningPorts()); String host = info.getHost(); int port = info.getPort(); addr = new EvoSuiteLocalAddress(host,port); } else { /* no point in creating local addresses that the SUT has never accessed */ addr = null; } setValue(addr); } }
@Override public void randomize() { String url = Randomness.choice(tc.getAccessedEnvironment().getViewOfRemoteURLs()); if (url != null) { setValue(new EvoSuiteURL(url)); } else { setValue(null); } } }
private void handleJEE(TestCase test) { JeeData jeeData = TestDataJavaEE.getInstance().getJeeData(); test.getAccessedEnvironment().setJeeData(jeeData); if (jeeData.lookedUpContextNames.size() > 0) { addEnvironmentClassToCluster(EvoNamingContext.class); // TODO add method with right input type } if (!Properties.HANDLE_SERVLETS) { /* * Started to prepare custom mocks for Servlets, but then realized * that their behavior is very basic. As such, most likely they are * not needed, as they could be much better replaced by functional * mocks with Mockito... */ return; } if (jeeData.wasAServletInitialized) { addEnvironmentClassToCluster(EvoServletState.class); } // TODO TestDataJavaEE data for Servlets }
if(properties!=null && properties.length>0){ for(String property : properties){ if(! tc.getAccessedEnvironment().hasProperty(property)){ return false;
@Override public void randomize() { JeeData data = tc.getAccessedEnvironment().getJeeData(); if(data == null){ setValue(null); return; } String name = Randomness.choice(data.lookedUpContextNames); if(name != null){ setValue(new EvoName(name)); } else { setValue(null); } } }
test.getAccessedEnvironment() .addLocalListeningPorts(VirtualNetwork.getInstance().getViewOfLocalListeningPorts()); test.getAccessedEnvironment().addRemoteURLs(VirtualNetwork.getInstance().getViewOfRemoteAccessedFiles()); test.getAccessedEnvironment() .addRemoteContactedPorts(VirtualNetwork.getInstance().getViewOfRemoteContactedPorts()); if (!hasAddedRemoteURLs && test.getAccessedEnvironment().getViewOfRemoteURLs().size() > 0) { hasAddedRemoteURLs = true; try { boolean openedUDP = false; for (EndPointInfo info : test.getAccessedEnvironment().getViewOfLocalListeningPorts()) { if (info.getType().equals(VirtualNetwork.ConnectionType.TCP)) { openedTCP = true; if (!hasAddedTcpRemoteSupport && test.getAccessedEnvironment().getViewOfRemoteContactedPorts().size() > 0) { hasAddedTcpRemoteSupport = true;
@Override public void randomize() { EvoSuiteRemoteAddress addr; double threshold = 0.8; //TODO parameter boolean accessed = Randomness.nextDouble() <= threshold; if(accessed && !tc.getAccessedEnvironment().getViewOfRemoteContactedPorts().isEmpty()){ // use an address that the SUT tried to contact EndPointInfo info = Randomness.choice(tc.getAccessedEnvironment().getViewOfRemoteContactedPorts()); String host = info.getHost(); int port = info.getPort();//TODO check why it can be a 0 here port = getPort(port); addr = new EvoSuiteRemoteAddress(host,port); } else { /* make up an address based on string/int constants. this is needed to handle the cases when the SUT get an incoming message, and then check its remote address. TODO: here we could validate if host/port values are indeed valid. However, as this is kind of special case, and likely not so common, it doesn't have high priority. */ ConstantPool constantPool = ConstantPoolManager.getInstance().getConstantPool(); String host = constantPool.getRandomString(); int port = constantPool.getRandomInt(); port = getPort(port); addr = new EvoSuiteRemoteAddress(host,port); } setValue(addr); }
test.getAccessedEnvironment().clear();