<commit_before>/*******************************************************************************
 * Copyright (c) 2017 Pivotal, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Pivotal, Inc. - initial API and implementation
 *******************************************************************************/
package org.springframework.ide.vscode.manifest.yaml;

import static org.junit.Assert.assertEquals;

import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.ide.vscode.languageserver.testharness.Editor;
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;

/**
 * Basic CF tests for services and buildpacks, using a basic CF client that
 * requires no actual CF connection.
 * 
 * <p/>
 * This is an alternative to using mockito, and also tests that the
 * vscode-manifest framework can take any clients, including the basic one used
 * in this test, and still function as expected for CF content assist and
 * reconcile
 *
 */
public class ManifestYamlEditorCFBasicTest {
	LanguageServerHarness harness;
	BasicCfClientHarness basicCfClientHarness = new BasicCfClientHarness();

	@Before
	public void setup() throws Exception {
		harness = new LanguageServerHarness(() -> new ManifestYamlLanguageServer(
				basicCfClientHarness.getBasicClientFactory(), basicCfClientHarness.getParamsProvider()));
		harness.intialize(null);
	}

	@Test
	public void contentAssistBuildpack() throws Exception {
		basicCfClientHarness.addBuildpacks("java_buildpack");
		assertContainsCompletions("buildpack: <*>", "buildpack: java_buildpack<*>");
	}

	@Test
	public void contentAssistDoesNotContainBuildpack() throws Exception {
		basicCfClientHarness.addBuildpacks("java_buildpack");
		assertDoesNotContainCompletions("buildpack: <*>", "buildpack: wrong_buildpack<*>");
	}

	@Ignore
	@Test
	public void contentAssistServices() throws Exception {
		basicCfClientHarness.addServiceInstances("mysql");
		assertContainsCompletions("services:\n" + " - <*>", "mysql");
	}

	@Test
	public void reconcileCFService() throws Exception {
		basicCfClientHarness.addServiceInstances("myservice");
		Editor editor = harness.newEditor("applications:\n" //
				+ "- name: foo\n" //
				+ "  services:\n" //
				+ "  - myservice\n" //
		);
		// Should have no problems
		editor.assertProblems(/* none */);
	}

	@Test
	public void reconcileShowsWarningOnUnknownService() throws Exception {
		basicCfClientHarness.addServiceInstances("myservice");
		Editor editor = harness.newEditor("applications:\n" //
				+ "- name: foo\n" //
				+ "  services:\n" //
				+ "  - bad-service\n" //

		);
		editor.assertProblems("bad-service|There is no service instance called");<commit_msg>Fixed failing test case for services<commit_after>/*******************************************************************************
 * Copyright (c) 2017 Pivotal, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Pivotal, Inc. - initial API and implementation
 *******************************************************************************/
package org.springframework.ide.vscode.manifest.yaml;

import static org.junit.Assert.assertEquals;

import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.ide.vscode.languageserver.testharness.Editor;
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;

/**
 * Basic CF tests for services and buildpacks, using a basic CF client that
 * requires no actual CF connection.
 * 
 * <p/>
 * This is an alternative to using mockito, and also tests that the
 * vscode-manifest framework can take any clients, including the basic one used
 * in this test, and still function as expected for CF content assist and
 * reconcile
 *
 */
public class ManifestYamlEditorCFBasicTest {
	LanguageServerHarness harness;
	BasicCfClientHarness basicCfClientHarness = new BasicCfClientHarness();

	@Before
	public void setup() throws Exception {
		harness = new LanguageServerHarness(() -> new ManifestYamlLanguageServer(
				basicCfClientHarness.getBasicClientFactory(), basicCfClientHarness.getParamsProvider()));
		harness.intialize(null);
	}

	@Test
	public void contentAssistBuildpack() throws Exception {
		basicCfClientHarness.addBuildpacks("java_buildpack");
		assertContainsCompletions("buildpack: <*>", "buildpack: java_buildpack<*>");
	}

	@Test
	public void contentAssistDoesNotContainBuildpack() throws Exception {
		basicCfClientHarness.addBuildpacks("java_buildpack");
		assertDoesNotContainCompletions("buildpack: <*>", "buildpack: wrong_buildpack<*>");
	}

	@Test
	public void contentAssistServices() throws Exception {
		basicCfClientHarness.addServiceInstances("mysql");
		assertContainsCompletions("services:\n" + "  - <*>", "mysql");
	}

	@Test
	public void reconcileCFService() throws Exception {
		basicCfClientHarness.addServiceInstances("myservice");
		Editor editor = harness.newEditor("applications:\n" //
				+ "- name: foo\n" //
				+ "  services:\n" //
				+ "  - myservice\n" //
		);
		// Should have no problems
		editor.assertProblems(/* none */);
	}

	@Test
	public void reconcileShowsWarningOnUnknownService() throws Exception {
		basicCfClientHarness.addServiceInstances("myservice");
		Editor editor = harness.newEditor("applications:\n" //
				+ "- name: foo\n" //
				+ "  services:\n" //
				+ "  - bad-service\n" //

		);
		editor.assertProblems("bad-service|There is no service instance called");
{'fraction_non_alphanumeric': 0.1562859490550534, 'fraction_numerical': 0.003286770747740345, 'mean_word_length': 5.043694141012909, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6208965', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1712, 'n_words': 425}