-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from hmrc/MIPR-1067
MIPR-1067: Added initial tests
- Loading branch information
Showing
29 changed files
with
1,168 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...axpenaltiesappealsfrontend/featureswitch/api/controllers/FeatureSwitchApiController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed 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 uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.api.controllers | ||
|
||
import play.api.libs.json.Json | ||
import play.api.mvc.{Action, AnyContent, InjectedController} | ||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.api.services.FeatureSwitchService | ||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.config.AppConfig | ||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.core.config.FeatureSwitching | ||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.core.models.FeatureSwitchSetting | ||
|
||
import javax.inject.{Inject, Singleton} | ||
|
||
@Singleton | ||
class FeatureSwitchApiController @Inject()(featureSwitchService: FeatureSwitchService, | ||
val config: AppConfig) extends InjectedController with FeatureSwitching { | ||
|
||
def getFeatureSwitches: Action[AnyContent] = Action { | ||
Ok(Json.toJson(featureSwitchService.getFeatureSwitches())) | ||
} | ||
|
||
def updateFeatureSwitches(): Action[Seq[FeatureSwitchSetting]] = Action(parse.json[Seq[FeatureSwitchSetting]]) { | ||
req => | ||
val updatedFeatureSwitches = featureSwitchService.updateFeatureSwitches(req.body) | ||
Ok(Json.toJson(updatedFeatureSwitches)) | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...c/incometaxpenaltiesappealsfrontend/featureswitch/api/services/FeatureSwitchService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed 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 uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.api.services | ||
|
||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.config.AppConfig | ||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.core.config.{FeatureSwitchRegistry, FeatureSwitching} | ||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.core.models.FeatureSwitchSetting | ||
|
||
import javax.inject.{Inject, Singleton} | ||
|
||
@Singleton | ||
class FeatureSwitchService @Inject()(featureSwitchRegistry: FeatureSwitchRegistry, | ||
val config: AppConfig) extends FeatureSwitching { | ||
|
||
def getFeatureSwitches(): Seq[FeatureSwitchSetting] = | ||
featureSwitchRegistry.switches.map( | ||
switch => | ||
FeatureSwitchSetting( | ||
switch.configName, | ||
switch.displayName, | ||
isEnabled(switch) | ||
) | ||
) | ||
|
||
def updateFeatureSwitches(updatedFeatureSwitches: Seq[FeatureSwitchSetting]): Seq[FeatureSwitchSetting] = { | ||
updatedFeatureSwitches.foreach( | ||
featureSwitchSetting => | ||
featureSwitchRegistry.get(featureSwitchSetting.configName).foreach { | ||
featureSwitch => | ||
if (featureSwitchSetting.isEnabled) enable(featureSwitch) else disable(featureSwitch) | ||
} | ||
) | ||
|
||
getFeatureSwitches() | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...c/incometaxpenaltiesappealsfrontend/featureswitch/core/config/FeatureSwitchRegistry.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed 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 uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.core.config | ||
|
||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.core.models.FeatureSwitch | ||
|
||
trait FeatureSwitchRegistry { | ||
|
||
def switches: Seq[FeatureSwitch] | ||
|
||
def apply(name: String): FeatureSwitch = | ||
get(name) match { | ||
case Some(switch) => switch | ||
case None => throw new IllegalArgumentException("Invalid feature switch: " + name) | ||
} | ||
|
||
def get(name: String): Option[FeatureSwitch] = switches find (_.configName == name) | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...v/hmrc/incometaxpenaltiesappealsfrontend/featureswitch/core/config/FeatureSwitching.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed 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 uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.core.config | ||
|
||
import play.api.Logging | ||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.config.AppConfig | ||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.core.models.FeatureSwitch | ||
|
||
trait FeatureSwitching extends Logging { | ||
|
||
val config: AppConfig | ||
|
||
val FEATURE_SWITCH_ON = "true" | ||
val FEATURE_SWITCH_OFF = "false" | ||
|
||
def isEnabled(featureSwitch: FeatureSwitch): Boolean = | ||
sys.props get featureSwitch.configName match { | ||
case Some(value) => value == FEATURE_SWITCH_ON | ||
case None => config.getFeatureSwitchValue(featureSwitch.configName) | ||
} | ||
|
||
def enable(featureSwitch: FeatureSwitch): Unit = { | ||
logger.warn(s"[enable] $featureSwitch") | ||
sys.props += featureSwitch.configName -> FEATURE_SWITCH_ON | ||
} | ||
|
||
def disable(featureSwitch: FeatureSwitch): Unit = { | ||
logger.warn(s"[disable] $featureSwitch") | ||
sys.props += featureSwitch.configName -> FEATURE_SWITCH_OFF | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
.../incometaxpenaltiesappealsfrontend/featureswitch/core/config/FeatureSwitchingModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed 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 uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.core.config | ||
|
||
import play.api.inject.{Binding, Module} | ||
import play.api.{Configuration, Environment} | ||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.core.models.FeatureSwitch | ||
|
||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class FeatureSwitchingModule extends Module with FeatureSwitchRegistry { | ||
|
||
val switches: Seq[FeatureSwitch] = Seq( | ||
UseStubForBackend | ||
) | ||
|
||
override def bindings(environment: Environment, configuration: Configuration): Seq[Binding[_]] = { | ||
Seq( | ||
bind[FeatureSwitchRegistry].to(this).eagerly() | ||
) | ||
} | ||
} | ||
|
||
case object UseStubForBackend extends FeatureSwitch { | ||
override val configName: String = "features.useStubForBackend" | ||
override val displayName: String = "Use stub instead of Penalties backend service" | ||
} |
22 changes: 22 additions & 0 deletions
22
.../gov/hmrc/incometaxpenaltiesappealsfrontend/featureswitch/core/models/FeatureSwitch.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed 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 uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.core.models | ||
|
||
trait FeatureSwitch { | ||
val configName: String | ||
val displayName: String | ||
} |
30 changes: 30 additions & 0 deletions
30
...rc/incometaxpenaltiesappealsfrontend/featureswitch/core/models/FeatureSwitchSetting.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed 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 uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.core.models | ||
|
||
import play.api.libs.json.{Json, OFormat} | ||
|
||
|
||
case class FeatureSwitchSetting(configName: String, | ||
displayName: String, | ||
isEnabled: Boolean) | ||
|
||
object FeatureSwitchSetting { | ||
|
||
implicit val format: OFormat[FeatureSwitchSetting] = Json.format[FeatureSwitchSetting] | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...xpenaltiesappealsfrontend/featureswitch/frontend/config/FeatureSwitchProviderConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed 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 uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.frontend.config | ||
|
||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.config.AppConfig | ||
import uk.gov.hmrc.incometaxpenaltiesappealsfrontend.featureswitch.frontend.models.FeatureSwitchProvider | ||
|
||
import javax.inject.{Inject, Singleton} | ||
|
||
@Singleton | ||
class FeatureSwitchProviderConfig @Inject()(appConfig: AppConfig) { | ||
|
||
lazy val selfBaseUrl: String = appConfig.selfUrl | ||
|
||
lazy val selfFeatureSwitchUrl = s"$selfBaseUrl/penalties-appeals/income-tax/test-only/api/feature-switches" | ||
|
||
lazy val selfFeatureSwitchProvider: FeatureSwitchProvider = FeatureSwitchProvider( | ||
id = "income-tax-penalties-appeals-frontend", | ||
appName = "Income Tax Penalties Appeals Frontend", | ||
url = selfFeatureSwitchUrl | ||
) | ||
|
||
lazy val featureSwitchProviders: Seq[FeatureSwitchProvider] = | ||
Seq(selfFeatureSwitchProvider) | ||
|
||
} |
Oops, something went wrong.