/******************************************************************************* | |
* Copyright (C) 2017 ANSYS medini Technologies AG | |
* | |
* This program and the accompanying materials are made | |
* available under the terms of the Eclipse Public License 2.0 | |
* which is available at https://www.eclipse.org/legal/epl-2.0/ | |
* | |
* SPDX-License-Identifier: EPL-2.0 | |
* | |
* Contributors: | |
* ANSYS medini Technologies AG - initial API and implementation | |
******************************************************************************/ | |
package org.eclipse.opencert.elastic; | |
import java.util.List; | |
import java.util.Set; | |
import org.eclipse.uml2.uml.Component; | |
import org.junit.Assert; | |
import org.junit.Test; | |
public class ElasticClientTest { | |
@Test | |
public void testPing() throws Exception { | |
System.out.println("Send a ping to local Elastic server..."); | |
ElasticClientImpl.on("localhost", 9200, "http").ping().close(); | |
System.out.println("Done. Server seems to be alive."); | |
} | |
@Test | |
public void testSend() throws Exception { | |
Component object = TestData.createComponent(); | |
ElasticDocument document = EObjectToDocument.INSTANCE.convert(object, "amass-test"); | |
ElasticClientImpl.on("localhost", 9200, "http").store(document).close(); | |
} | |
@Test | |
public void testDelete() throws Exception { | |
ElasticClientImpl.on("localhost", 9200, "http").delete("amass-test").close(); | |
} | |
@Test | |
public void testSendMany() throws Exception { | |
List<ElasticDocument> documents = EObjectToDocument.INSTANCE.convert(TestData.uml(50), "amass-test"); | |
ElasticClientImpl.on("localhost", 9200, "http").storeAll(documents.iterator()).close(); | |
} | |
@Test | |
public void testSendAndSearch() throws Exception { | |
Component object = TestData.createComponent(); | |
ElasticDocument document = EObjectToDocument.INSTANCE.convert(object, "amass-test"); | |
ElasticClient client = ElasticClientImpl.on("localhost", 9200, "http").delete("amass-test").store(document); | |
Set<ElasticDocument> hits = client.search("amass-test", null, null); | |
Assert.assertEquals(1, hits.size()); | |
// | |
hits = client.search("amass-test", "foobar", null); | |
Assert.assertEquals(0, hits.size()); | |
client.close(); | |
} | |
} |