|
| 1 | +/******************************************************************************* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2011 - 2015 OpenWorm. |
| 5 | + * http://openworm.org |
| 6 | + * |
| 7 | + * All rights reserved. This program and the accompanying materials |
| 8 | + * are made available under the terms of the MIT License |
| 9 | + * which accompanies this distribution, and is available at |
| 10 | + * http://opensource.org/licenses/MIT |
| 11 | + * |
| 12 | + * Contributors: |
| 13 | + * OpenWorm - http://openworm.org/people.html |
| 14 | + * |
| 15 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 16 | + * of this software and associated documentation files (the "Software"), to deal |
| 17 | + * in the Software without restriction, including without limitation the rights |
| 18 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 19 | + * copies of the Software, and to permit persons to whom the Software is |
| 20 | + * furnished to do so, subject to the following conditions: |
| 21 | + * |
| 22 | + * The above copyright notice and this permission notice shall be included in |
| 23 | + * all copies or substantial portions of the Software. |
| 24 | + * |
| 25 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 26 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 27 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 28 | + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 29 | + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 30 | + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 31 | + * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 32 | + *******************************************************************************/ |
| 33 | +package org.geppetto.datasources; |
| 34 | + |
| 35 | +import java.io.IOException; |
| 36 | +import java.io.InputStream; |
| 37 | +import java.util.HashMap; |
| 38 | +import java.util.Map; |
| 39 | + |
| 40 | +import junit.framework.Assert; |
| 41 | + |
| 42 | +import org.geppetto.core.common.GeppettoCommonUtils; |
| 43 | +import org.geppetto.core.datasources.GeppettoDataSourceException; |
| 44 | +import org.geppetto.core.datasources.VelocityUtils; |
| 45 | +import org.geppetto.model.GeppettoFactory; |
| 46 | +import org.geppetto.model.SimpleQuery; |
| 47 | +import org.junit.Before; |
| 48 | +import org.junit.Test; |
| 49 | + |
| 50 | +/** |
| 51 | + * @author matteocantarelli |
| 52 | + * |
| 53 | + */ |
| 54 | +public class VelocityUtilsTest |
| 55 | +{ |
| 56 | + |
| 57 | + /** |
| 58 | + * @throws java.lang.Exception |
| 59 | + */ |
| 60 | + @Before |
| 61 | + public void setUp() throws Exception |
| 62 | + { |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Test method for {@link org.geppetto.core.datasources.VelocityUtils#processTemplate(java.lang.String, java.util.Map)}. |
| 67 | + * |
| 68 | + * @throws GeppettoDataSourceException |
| 69 | + * @throws IOException |
| 70 | + */ |
| 71 | + @Test |
| 72 | + public void testProcessTemplate() throws GeppettoDataSourceException, IOException |
| 73 | + { |
| 74 | + SimpleQuery query = GeppettoFactory.eINSTANCE.createSimpleQuery(); |
| 75 | + query.setQuery("MATCH (n:Class)<-[:SUBCLASSOF*]-(:Class)<-[:INSTANCEOF]-(i) WHERE n.short_form='$ID' RETURN n AS columnName limit 5;"); |
| 76 | + Map<String, Object> properties = new HashMap<String, Object>(); |
| 77 | + properties.put("ID", "FBbt_00100219"); |
| 78 | + properties.put("QUERY", query.getQuery()); |
| 79 | + String queryString = VelocityUtils.processTemplate("/templates/neo4j/queryTemplate.vm", properties); |
| 80 | + InputStream in = VelocityUtilsTest.class.getClassLoader().getResourceAsStream("expectedQueryTemplateResultTest.json"); |
| 81 | + String expected = GeppettoCommonUtils.readString(in); |
| 82 | + Assert.assertEquals(expected, queryString); |
| 83 | + } |
| 84 | + |
| 85 | +} |
0 commit comments