|
@@ -0,0 +1,89 @@
|
|
|
+/*
|
|
|
+ * Licensed to the Apache Software Foundation (ASF) under one
|
|
|
+ * or more contributor license agreements. See the NOTICE file
|
|
|
+ * distributed with this work for additional information
|
|
|
+ * regarding copyright ownership. The ASF 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.apache.ambari.server.upgrade;
|
|
|
+
|
|
|
+import static org.easymock.EasyMock.createNiceMock;
|
|
|
+import static org.easymock.EasyMock.createStrictMock;
|
|
|
+import static org.easymock.EasyMock.expect;
|
|
|
+import static org.easymock.EasyMock.expectLastCall;
|
|
|
+import static org.easymock.EasyMock.replay;
|
|
|
+import static org.easymock.EasyMock.reset;
|
|
|
+import static org.easymock.EasyMock.verify;
|
|
|
+
|
|
|
+import javax.persistence.EntityManager;
|
|
|
+
|
|
|
+import org.apache.ambari.server.orm.DBAccessor;
|
|
|
+import org.apache.ambari.server.state.stack.OsFamily;
|
|
|
+import org.junit.After;
|
|
|
+import org.junit.Before;
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
+import com.google.inject.Binder;
|
|
|
+import com.google.inject.Guice;
|
|
|
+import com.google.inject.Injector;
|
|
|
+import com.google.inject.Module;
|
|
|
+import com.google.inject.Provider;
|
|
|
+
|
|
|
+/**
|
|
|
+ * {@link UpgradeCatalog250} unit tests.
|
|
|
+ */
|
|
|
+public class UpgradeCatalog250Test {
|
|
|
+
|
|
|
+// private Injector injector;
|
|
|
+ private Provider<EntityManager> entityManagerProvider = createStrictMock(Provider.class);
|
|
|
+ private EntityManager entityManager = createNiceMock(EntityManager.class);
|
|
|
+
|
|
|
+ @Before
|
|
|
+ public void init() {
|
|
|
+ reset(entityManagerProvider);
|
|
|
+ expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
|
|
|
+ replay(entityManagerProvider);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @After
|
|
|
+ public void tearDown() {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testExecuteDDLUpdates() throws Exception {
|
|
|
+ final DBAccessor dbAccessor = createNiceMock(DBAccessor.class);
|
|
|
+
|
|
|
+ dbAccessor.addUniqueConstraint("host_version", "UQ_host_repo", "repo_version_id", "host_id");
|
|
|
+ expectLastCall().once();
|
|
|
+
|
|
|
+ replay(dbAccessor);
|
|
|
+
|
|
|
+ Module module = new Module() {
|
|
|
+ @Override
|
|
|
+ public void configure(Binder binder) {
|
|
|
+ binder.bind(DBAccessor.class).toInstance(dbAccessor);
|
|
|
+ binder.bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
|
|
|
+ binder.bind(EntityManager.class).toInstance(entityManager);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ Injector injector = Guice.createInjector(module);
|
|
|
+ UpgradeCatalog250 upgradeCatalog250 = injector.getInstance(UpgradeCatalog250.class);
|
|
|
+ upgradeCatalog250.executeDDLUpdates();
|
|
|
+
|
|
|
+ verify(dbAccessor);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|