<commit_before>package eu.cloudopting.dockertests;

import static org.junit.Assert.*;

import org.apache.log4j.spi.LoggerFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import eu.cloudopting.docker.DockerError;
import eu.cloudopting.docker.DockerService;
import eu.cloudopting.docker.config.DockerConfig;


/**
 * Tests for cloudopting-crane
 */
@ContextConfiguration(classes = {DockerConfig.class})
@RunWith(SpringJUnit4ClassRunner.class)
public class DockerTests {

    @Autowired
    private DockerService dockerService;
	
	// Connections tests
    
    @Test
    public void testConnection() {   
        assertTrue("Crane is not alive or it is not responding as expected.", dockerService.isCraneAlive());
    }
    
    // Building related test
	
    @Test
    public void testNewContext() {
    	boolean correct = false;
    	String token = "";
    	try {
			token = dockerService.newContext("src/test/resources/testfiles/Puppetfile");
		} catch (DockerError e) {
		}
    	
    	if(token=="exists")
    		correct = true;
    	
        assertTrue("token:."+token, correct);
    }
    
    @Test
    public void testCheckContext() {   
        assertNotNull("Not yet.", null);
    }
    
    @Test
    public void testGetContextInfo() {   
    	assertNotNull("Not yet.", null);
    }
    
    @Test
    public void testRemoveContext() {   
    	assertNotNull("Not yet.", null);
    }
    
    @Test
    public void testBuildImage() {   
    	assertNotNull("Not yet.", null);
    }
    
    @Test
    public void testCheckImage() {   
    	assertNotNull("Not yet.", null);
    }
    
    @Test
    public void testGetImageInfo() {   
    	assertNotNull("Not yet.", null);
    }
    
    @Test
    public void testStopBuild() {   
    	assertNotNull("Not yet.", null);
    }
    
    @Test
    public void testCommitImage() {   
    	assertNotNull("Not yet.", null);
    }
    
    @Test
    public void testCheckCommitImage() {   
    	assertNotNull("Not yet.", null);<commit_msg>New tests. Build image test need some attention in order to fix possible infinite loop.<commit_after>package eu.cloudopting.dockertests;

import static org.junit.Assert.*;

import java.util.Map;

import org.apache.log4j.spi.LoggerFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.json.BasicJsonParser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import eu.cloudopting.docker.DockerError;
import eu.cloudopting.docker.DockerService;
import eu.cloudopting.docker.config.DockerConfig;


/**
 * Tests for cloudopting-crane
 */
@ContextConfiguration(classes = {DockerConfig.class})
@RunWith(SpringJUnit4ClassRunner.class)
public class DockerTests {

    @Autowired
    private DockerService dockerService;
	
	// Connections tests
    
    @Test
    public void testConnection() {   
        assertTrue("Crane is not alive or it is not responding as expected.", dockerService.isCraneAlive());
    }
    
    // Building related tests
	
    @Test
    public void testNewContext() {
    	boolean correct = false;
    	String token = "";
    	
    	try {
			token = dockerService.newContext("src/test/resources/testfiles/Puppetfile");
		} catch (DockerError e) {
		}
    	
    	if(token!=null && token!="")
    		correct = true;
    	
        assertTrue("Can't obtain a valid context token from Crane.", correct);
    }
    
    @Test
    public void testCheckContext() {   
       	boolean correct = false;
    	
    	try {
    		String token = dockerService.newContext("src/test/resources/testfiles/Puppetfile");
			dockerService.isContextReady(token);
			correct = true;
		} catch (DockerError e) {
		}
    	
        assertTrue("Error while consulting context build status.", correct);
    }
    
    @Test
    public void testGetContextInfo() {   
       	boolean correct = false;
    	
    	try {
    		String token = dockerService.newContext("src/test/resources/testfiles/Puppetfile");
			String response = dockerService.getContextInfo(token);
			
			BasicJsonParser parser = new BasicJsonParser();
			Map<String, Object> map = parser.parseMap(response);
			
			if(map.get("status").toString() != null && map.get("description").toString() != null){
				correct = true;
			}
			
		} catch (DockerError e) {
		}
    	
        assertTrue("Error while consulting context build status.", correct);
    }
    
    @Test
    public void testRemoveContext() {   
       	boolean correct = false;
    	String token;
    	
    	try {
    		token = dockerService.newContext("src/test/resources/testfiles/Puppetfile");
			dockerService.removeContext(token);
			
			try{
				dockerService.isContextReady(token);
			}catch (DockerError e){
				correct = true;
			}
			
		} catch (DockerError e) {
		}
    	
        assertTrue("Error while removing context.", correct);
    }
    
    @Test
    public void testBuildImage() {   
       	boolean correct = false;
    	
    	try {
    		// Prepare context
    		String contextToken = dockerService.newContext("src/test/resources/testfiles/Puppetfile");
			
    		while(dockerService.isContextReady(contextToken)!=true)
    			Thread.sleep(1000);

			// Launch image builder
    		String response = dockerService.buildDockerImage("apache12", "src/test/resources/testfiles/Dockerfile", "src/test/resources/testfiles/lamp.pp", contextToken);
    		
    		// Check response
			BasicJsonParser parser = new BasicJsonParser();
			Map<String, Object> map = parser.parseMap(response);
			
			if(map.get("status").toString() == "building" || map.get("status").toString() != "finished"){
				correct = true;
			}
			
		} catch (DockerError e) {
		} catch(InterruptedException ex) {
			Thread.currentThread().interrupt();
		}
    	
        assertTrue("Error while building image.", correct);
    }
    
    @Test
    public void testCheckImage() {   
    	assertNotNull("Not yet.", null);
    }
    
    @Test
    public void testGetImageInfo() {   
    	assertNotNull("Not yet.", null);
    }
    
    @Test
    public void testStopBuild() {   
    	assertNotNull("Not yet.", null);
    }
    
    @Test
    public void testCommitImage() {   
    	assertNotNull("Not yet.", null);
    }
    
    @Test
    public void testCheckCommitImage() {   
    	assertNotNull("Not yet.", null);
{'fraction_non_alphanumeric': 0.11239018479248712, 'fraction_numerical': 0.0021205695243865495, 'mean_word_length': 2.8256083429895713, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4942219', 'n_tokens_mistral': 2082, 'n_tokens_neox': 1966, 'n_words': 418}