1+ // Licensed to the Apache Software Foundation (ASF) under one
2+ // or more contributor license agreements. See the NOTICE file
3+ // distributed with this work for additional information
4+ // regarding copyright ownership. The ASF licenses this file
5+ // to you under the Apache License, Version 2.0 (the
6+ // "License"); you may not use this file except in compliance
7+ // with the License. You may obtain a copy of the License at
8+ //
9+ // http://www.apache.org/licenses/LICENSE-2.0
10+ //
11+ // Unless required by applicable law or agreed to in writing,
12+ // software distributed under the License is distributed on an
13+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+ // KIND, either express or implied. See the License for the
15+ // specific language governing permissions and limitations
16+ // under the License.
17+ package com .cloud .upgrade ;
18+
19+ import com .cloud .upgrade .dao .DbUpgrade ;
20+ import com .cloud .upgrade .dao .Upgrade41110to41120 ;
21+ import com .cloud .upgrade .dao .Upgrade41120to41130 ;
22+ import com .cloud .upgrade .dao .Upgrade41120to41200 ;
23+ import com .cloud .upgrade .dao .Upgrade41500to41510 ;
24+ import com .cloud .upgrade .dao .Upgrade41510to41520 ;
25+ import com .cloud .upgrade .dao .Upgrade41520to41600 ;
26+ import com .cloud .upgrade .dao .Upgrade41720to41800 ;
27+ import com .cloud .upgrade .dao .Upgrade481to490 ;
28+ import org .apache .cloudstack .utils .CloudStackVersion ;
29+ import org .junit .jupiter .api .BeforeAll ;
30+ import org .junit .jupiter .api .Test ;
31+
32+ import java .io .InputStream ;
33+ import java .sql .Connection ;
34+
35+ import static org .junit .jupiter .api .Assertions .assertEquals ;
36+
37+ class DatabaseVersionHierarchyTest {
38+
39+ private static DatabaseVersionHierarchy hierarchy ;
40+
41+ static class DummyUpgrade implements DbUpgrade {
42+ @ Override
43+ public String [] getUpgradableVersionRange () {
44+ return new String [0 ];
45+ }
46+
47+ @ Override
48+ public String getUpgradedVersion () {
49+ return null ;
50+ }
51+
52+ @ Override
53+ public boolean supportsRollingUpgrade () {
54+ return false ;
55+ }
56+
57+ @ Override
58+ public InputStream [] getPrepareScripts () {
59+ return new InputStream [0 ];
60+ }
61+
62+ @ Override
63+ public void performDataMigration (Connection conn ) {
64+
65+ }
66+
67+ @ Override
68+ public InputStream [] getCleanupScripts () {
69+ return new InputStream [0 ];
70+ }
71+
72+ }
73+
74+ @ BeforeAll
75+ static void init () {
76+ DatabaseVersionHierarchy .DatabaseVersionHierarchyBuilder builder = DatabaseVersionHierarchy .builder ()
77+ .next ("0.0.5" , new DummyUpgrade ())
78+ .next ("1.0.0.0" , new DummyUpgrade ())
79+ .next ("1.0.1" , new DummyUpgrade ())
80+ .next ("1.2.0" , new DummyUpgrade ())
81+ .next ("2.0.0" , new DummyUpgrade ())
82+ .next ("2.3.2" , new DummyUpgrade ())
83+ .next ("3.4.5.6" , new DummyUpgrade ())
84+ .next ("4.8.2.0" , new Upgrade481to490 ())
85+ .next ("4.9.10.11" , new DummyUpgrade ())
86+ .next ("4.11.1.0" , new Upgrade41110to41120 ())
87+ .next ("4.11.2.0" , new Upgrade41120to41130 ())
88+ .next ("4.11.3.0" , new Upgrade41120to41200 ())
89+ .next ("4.15.0.0" , new Upgrade41500to41510 ())
90+ .next ("4.15.1.0" , new Upgrade41510to41520 ())
91+ .next ("4.15.2.0" , new Upgrade41520to41600 ())
92+ .next ("4.15.4" , new DummyUpgrade ())
93+ .next ("4.17.2.0" , new Upgrade41720to41800 ());
94+ hierarchy = builder .build ();
95+ }
96+
97+ @ Test
98+ void getRecentVersionMiddle () {
99+ assertEquals ("2.0.0" , hierarchy .getRecentVersion (CloudStackVersion .parse ("2.2.2" )).toString ());
100+ }
101+ @ Test
102+ void getRecentVersionEarly () {
103+ assertEquals (null , hierarchy .getRecentVersion (CloudStackVersion .parse ("0.0.2" )));
104+ }
105+ @ Test
106+ void getRecentVersionStart () {
107+ assertEquals (null , hierarchy .getRecentVersion (CloudStackVersion .parse ("0.0.5" )));
108+ }
109+ @ Test
110+ void getRecentVersionJust () {
111+ assertEquals ("0.0.5" , hierarchy .getRecentVersion (CloudStackVersion .parse ("0.0.9" )).toString ());
112+ }
113+ @ Test
114+ void getRecentVersionExact () {
115+ assertEquals ("0.0.5" , hierarchy .getRecentVersion (CloudStackVersion .parse ("1.0.0.0" )).toString ());
116+ }
117+ }
0 commit comments