Skip to content

Instantly share code, notes, and snippets.

@anpieber
Created April 7, 2011 10:28
Show Gist options
  • Save anpieber/907510 to your computer and use it in GitHub Desktop.
Save anpieber/907510 to your computer and use it in GitHub Desktop.
/**
* Licensed to the Austrian Association for Software Tool Integration (AASTI)
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. The AASTI licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openengsb.core.persistence.internal;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.List;
import org.junit.Test;
import org.openengsb.core.api.model.ConfigItem;
import org.openengsb.core.api.model.RuleConfiguration;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
public class CorePersistenceServiceBackendTest {
@Test
public void testQuery_shouldFindPersistedFile() throws Exception {
Bundle bundleMock = mock(Bundle.class);
when(bundleMock.getSymbolicName()).thenReturn("testsymbolicname");
BundleContext bundleContextMock = mock(BundleContext.class);
when(bundleContextMock.getBundle()).thenReturn(bundleMock);
CorePersistenceServiceBackend corePersistenceServiceBackend = new CorePersistenceServiceBackend();
NeodatisPersistenceManager persistenceManager = new NeodatisPersistenceManager();
persistenceManager.setPersistenceRootDir("target/data");
corePersistenceServiceBackend.setPersistenceManager(persistenceManager);
corePersistenceServiceBackend.setBundleContext(bundleContextMock);
corePersistenceServiceBackend.init();
HashMap<String, String> meta = new HashMap<String, String>();
meta.put("test1", "test1");
meta.put("test2", "test2");
String rule = "rule";
RuleConfiguration ruleConfiguration = new RuleConfiguration(meta, rule);
corePersistenceServiceBackend.persist(ruleConfiguration);
HashMap<String, String> found = new HashMap<String, String>();
found.put("test1", "test1");
found.put("test2", "test2");
List<ConfigItem<?>> result = corePersistenceServiceBackend.load(meta);
assertThat(result, notNullValue());
assertThat(result.size(), is(1));
assertThat(result.get(0).getContent().toString(), is("rule"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment